1.更新列表apt-get
sudo apt-get update
2.安装MySQL服务端和客户端
sudo apt-get install mysql-server mysql-client
3.安装服务端时如未出现配置默认密码那就是没有密码输入如下命令回车进入mysql
mysql -u root -p
4.修改root用户密码,注意password字段不存在需修改为authentication_string进行修改
use mysql;
update mysql.user set authentication_string=password('root') where user='root' and Host ='localhost';
update user set plugin="mysql_native_password";
flush privileges;
quit;
5.设置编码修改/etc/mysql/my.cnf文件,添加如下内容:
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
character-set-server=utf8
6.进入mysql查看状态(编码是否为utf8)
status或者\s
7.开启和关闭mysql服务
开启:service mysql start
关闭:service mysql stop
重启:service mysql restart