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