- 首先,安装MySQL:
sudo apt-get install mysql-server
- 然后,查看初始用户名和密码。(注意:初始用户名不是root!)
sudo cat /etc/mysql/debian.cnf
复制里面的user和password!
- 然后,用上图的user和密码登录mysql,例如:
mysql -u 用户名 -p
然后输入密码即可。
- 创建root
use mysql;
update user set authentication_string='' where user='root';
然后
alter user 'root'@'localhost' identified with mysql_native_password by '密码';
这样你就有root啦!
- 创建远程访问数据库用的账号
create user 远程访问的用户名@'%' identified by '密码';
然后
GRANT all on *.* TO 远程访问的用户名@'%';
接下来需要更改设置,否则会遇到1251问题:
ALTER USER '远程访问的用户名'@'%' IDENTIFIED WITH mysql_native_password BY '密码';
OK!