Ubuntu系统中MySQL安装后基本配置
适用于MySQL 8.0,Ubuntu版本 > 18.04
Step 1. 检查默认账户和密码
$cat /etc/mysql/debian.cnf # 在ubuntu下查看默认账户名和密码
会看到
[client]
host = localhost
user = debian-sys-maint
password = ****************
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = ****************
socket = /var/run/mysqld/mysqld.sock
Step 2. 使用默认账户登录并修改root密码
$mysql -u debian-sys-maint -p
Enter password:
mysql> use mysql;
mysql> alter user 'root'@'localhost' identified with mysql_native_password by '****'
mysql> flush privileges;
mysql> exit;
$ sudo service mysql restart # 重启mysql服务
Step 3. 使用root登录
$ mysql -u root -p
Enter password:
mysql>