ubuntu mate下Mysql安装与初始密码更改
硬件:树莓派4b
找了好多的更改Mysql密码的方法,终于找到一个非常简便的,跟我一起走一遍就更改完了。
$ sudo apt update
$ sudo apt-get install mysql-server
$ sudo apt-get install mysql-client
使用root进入Mysql.
$ sudo cat /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = xxxxxxxxxxxxxxxxxxxxxxx(是你的密码)
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = xxxxxxxxxxxxxxxxxxxxxxx(是你的密码)
socket = /var/run/mysqld/mysqld.sock
$ mysql -u debian-sys-maint -p
Enter password:xxxxxxxxxxxxxxxxxxxxxxx(是你的密码)
密码很复杂,下一步更改密码。
$ sudo -s
//(进入ROOT)
# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
mysql> ALTER user 'root'@'localhost' IDENTIFIED BY '你的密码';
//密码包括 大小写字母,数字,和特殊字符,我用的特殊字符是'_',这个是可以应用的。
Query OK, 0 rows affected (0.02 sec)
//修改完成,使用exit指令退出后,再重新进入,可行。
现发现如果要登陆MYSQL需要sudo -s进入root权限,因此下一步可添加 用户,使用其他用户来使用mysql。
首先sudo -s进入root后,输入密码进入mysql。
键入以下指令。
mysql> create user Abc identified by 'Abc_1234';
//Abc : 自定义的用户名
//Abc_1234 : 自定义的密码
Query OK, 0 rows affected (0.04 sec)
mysql> exit
root@xxxxx:~# exit
xxx@xxxxx:~$ mysql -u Abc -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
此刻已经通过其他用户进入mysql,会发现之前的root用户下的database已经全部看不见了,需要进行下一步授权才可以共享database。