Ubuntu 18.04 安装 mysql 的过程中,竟然没有让你输入秘密?!(之前在 Ubuntu 14.04 下,安装过程中会询问密码),这导致安装完 mysql 初始秘密不知道的问题。
$ sudo apt-get install mysql-server-5.7
解决方法如下:
1)安装完成后,会生成文件 /etc/mysql/debian.cnf ,初始用户名和秘密如下 (这里密码是随机的)
$ sudo cat /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = 63vIY3PtyKh10cmZ
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = 63vIY3PtyKh10cmZ
socket = /var/run/mysqld/mysqld.sock
2)使用这个用户名和秘密登陆 mysql
$ mysql -h localhost -u debian-sys-maint -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id i