Ubuntu 18.04 安装配置 MySQL 5.7

1、安装MySQL5.7

sudo apt-get install mysql-server-5.7

2、安装完配置

# 查看初始安装后的用户名和密码
sudo cat /etc/mysql/debian.cnf 
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = HP6EwIvpXY23EQ3M
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = HP6EwIvpXY23EQ3M
socket   = /var/run/mysqld/mysqld.sock
# 修改密码
mysql -h localhost -u debian-sys-maint -p
Enter password: 
ysql> update mysql.user set authentication_string=password('******') where user='root' and host='localhost';
mysql> use mysql;
mysql> update user set plugin='mysql_native_password';
mysql> flush privileges;
mysql> quit;

3、重启mysql

sudo service mysql restart

# root用户登录
mysql -h localhost -u root -p
Enter password: 

# 查看数据库的字符集 character_set_database character_set_server 
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+

# 将其改为 utf8,打开 /etc/mysql/mysql.conf.d/mysqld.cnf,在最后添加一句character-set-server=utf8
# 重启mysql服务
sudo service mysql restart

参考:https://www.cnblogs.com/gaowengang/p/10816537.html

posted @ 2020-04-16 22:12  kayj  阅读(350)  评论(0编辑  收藏  举报