更新源
sudo apt-get update
安装
sudo apt-get install mysql-server
启动
service mysql start
登陆mysql,刚安装完无需密码
mysql -u root
查看你现在必须要了解的信息(用户,主机,加密相关)
use mysql;
select host,user,authentication_string,plugin from user;
一般来说第一次会是这样
+-----------+------------------+-------------------------------------------+-----------------------+
| host | user | authentication_string | plugin |
+-----------+------------------+-------------------------------------------+-----------------------+
| localhost | root | | auth_socket |
| localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password |
| localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password |
| localhost | debian-sys-maint | *954EA78C48797FB789E2E283FA243A23B7A69183 | mysql_native_password |
+-----------+------------------+-------------------------------------------+-----------------------+
修改root密码
update user set authentication_string=password("ln122920") where user='root';
修改加密方式(可能是这么叫)
update user set plugin='mysql_native_password' where user='root';
开放远程连接(仅限开发中使用,如不需要不用执行此行),云服务器需要在对应的管理网站开放3306端口
update user set host='%' where user='root';
刷新
flush privileges;
退出
exit
重新启动mysql服务
service mysql restart
登陆mysql
mysql -u root -p
然后输入密码并按回车,密码不会显示出来