Ubuntu20.04下安装并使用MySQL8.0
安装
sudo apt update
sudo apt install mysql-server
一旦安装完成,MySQL 服务将会自动启动。想要验证 MySQL 服务器正在运行,输入:
sudo systemctl status mysql
修改默认密码
MySql 从8.0开始修改密码有了变化,在user表加了字段authentication_string,修改密码前先检查authentication_string是否为空
use mysql;
update user set authentication_string='' where user='root';--将字段置为空
ALTER user 'root'@'localhost' IDENTIFIED BY 'root';--修改密码为root
flush privileges;
远程root 用户
如果需要远程登陆:
创建一个 host 字段为 % 的 root 用户(创建用户的同时设置密码)
create user 'root'@'%' identified by 'yourpassword';
授权所有数据库的访问权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
刷新权限列表
FLUSH PRIVILEGES;
注释bind-address = 127.0.0.1
vim /etc/mysql/mysql.conf.d/mysqld.cnf
重启MySQL
重启命令为:service mysql restart
或者service mysqld restart
本文来自博客园,作者:空唤晴,转载请注明原文链接:https://www.cnblogs.com/konghuanqing/p/16327567.html