一、安装mysql
sudo apt install -y mysql-server mysql-client
二、启动mysql
sudo systemctl start mysql
sudo systemctl enable mysql
三、连接mysql
四、重置root密码
参考:https://blog.csdn.net/r527665047/article/details/107056941/
1 修改配置文件/etc/mysql/mysql.conf.d/mysqld.cnf
- sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
2 在[mysqld]下添加skip-grant-tables
3 重启mysql
sudo systemctl restart mysql
4 直接用mysql -u root -p登录即可,(密码直接回车)
5 登录后操作
1.use mysql;
2.update user set authentication_string=password("ln122920"),plugin='mysql_native_password' where user='root';
3.flush privileges;
6 注销登录
7 将/etc/mysql/mysql.conf.d/mysqld.cnf文件中添加的内容注释
8 重新使用密码登录
mysql -u root -p
五、添加新用户
1.使用root登录mysql
mysql -u root -p
2.添加用户
create user 'web'@'localhost' identified by '123456';
3.授权
grant all privileges on *.* to web@localhost identified by '123456';