Ubuntu18.04(linux)安装MySQL的方法步骤
程序员文章站
2022-10-17 22:07:17
安装
mysql
sudo apt-get --purge remove mysql-server mysql-common mysql-client
sud...
安装
mysql
sudo apt-get --purge remove mysql-server mysql-common mysql-client sudo apt-get install mysql-server mysql-common mysql-client mysqladmin -u root password your-new-password sudo /etc/init.d/mysql restart
mariadb
apt-get install mariadb-server
字符集修改utf8
如果装的mariadb, 默认字符集已经是utf8了。mysql则不是
mysql> show variables like 'char%'; +--------------------------+----------------------------+ | variable_name | value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+
mysql> show variables like 'collation%'; +----------------------+-------------------+ | variable_name | value | +----------------------+-------------------+ | collation_connection | utf8_general_ci | | collation_database | latin1_swedish_ci | | collation_server | latin1_swedish_ci | +----------------------+-------------------+
修改字符集:
sudo vim /etc/mysql/my.cnf
添加以下内容
[mysqld] collation-server = utf8_unicode_ci init-connect='set names utf8' character-set-server = utf8
重启:
service mysql restart
登录权限问题
ubuntu18.04 安装mysql或者mariadb之后,发现普通用户和远程都没有权限连接。
error 1045: access denied for user: (using
password: yes)
修改了密码也不对。然后sudo mysql -u root
即可登录。这显然不是我们想要的。
解决方案
删除root,重新创建用户。
首先,登录
sudo mysql -u root
然后查看当前用户
select user,host from mysql.user; +------------------+-----------+ | user | host | +------------------+-----------+ | admin | localhost | | debian-sys-maint | localhost | | magento_user | localhost | | mysql.sys | localhost | | root | localhost |
删除root账号
mysql> drop user 'root'@'localhost'; query ok, 0 rows affected (0,00 sec)
重新创建root:
mysql> create user 'root'@'%' identified by '123456'; query ok, 0 rows affected (0,00 sec)
授权
mysql> grant all privileges on *.* to 'root'@'%' with grant option; query ok, 0 rows affected (0,00 sec) mysql> flush privileges; query ok, 0 rows affected (0,01 sec)
关于重置密码
host为%
时允许远程登录
set password for root@'localhost' = password('password');
or
update mysql.user set password=password('newpwd') where user='root';
or
use mysql update user set password = password('newpwd') where host = 'localhost' and user = 'root';
允许任何地方登录
use mysql update user set password = password('newpwd') where host = '%' and user = 'root';
参考
https://help.ubuntu.com/community/mysqlpasswordreset
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
推荐阅读
-
linux磁盘分区的详细步骤(图解linux分区命令使用方法)
-
Linux下设置可使用netpas网络加速器的方法与步骤介绍
-
Window 下安装Mysql5.7.17 及设置编码为utf8的方法
-
Hadoop安装配置Mysql数据库的步骤教程
-
Ubuntu安装MySQL5.7并配置数据存储路径的方法步骤
-
centos6利用yum安装php mysql gd的步骤
-
linux 安装setup.py程序的实现方法
-
centos7.2.1511安装jdk1.8.0_151及mysql5.6.38的方法
-
linux下pip的安装步骤及使用详解
-
在Linux系统中为Firefox安装最新版flash插件的方法