1 前言
由于没买云数据库,所以只好在云服务器上安装一个mysql,但是在安装过程中遇到root账户空密码的问题,查询了很久才解决,于是记录一下。
2 步骤
2.1 更新包列表
apt update
2.2 安装
apt install mysql-server
2.3 启动MySQL
sudo systemctl start mysql
2.4 查看状态
systemctl status mysql.service
2.5 设置开机自启动
systemctl enable mysql.service
2.6 修改mysql配置文件,允许远程连接:
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
#将bind-address = 127.0.0.1注销
#bind-address = 127.0.0.1
2.7 修改后重启mysql服务器
sudo /etc/init.d/mysql restart
2.8 登陆mysql初始的root用户
mysql -uroot -p;
2.9 修改初始的root密码,然后刷新
update mysql.user set authentication_string=password("你的密码") where user='root';
update mysql.user set plugin="mysql_native_password";
flush privileges;
2.10 创建并将所有权限,所有数据库,授予任意主机都能连接的root用户
grant all privileges on *.* to 'root'@'%' identified by '你的密码' with grant option;
2.11 刷新
FLUSH PRIVILEGES;
网友评论