ubuntu18 安装 mysql
一、 安装MySQL5.7
sudo apt-get install mysql-server-5.7
二、安装完配置
# 查看初始安装后的用户名和密码
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;
三、重启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
四、开启远程登录
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密码' WITH GRANT OPTION;
flush privileges;
五、修改配置文件
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
#注释 bind-address 配置