当前位置:网站首页>Ubuntu下安装mysql笔记

Ubuntu下安装mysql笔记

2022-08-11 05:24:00 Three Big Stones

1.首先更新本地存储库索引,执行sudo apt update

2.执行安装命令:sudo apt install mysql-server -y,遇到下面的报错

E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

执行删除命令:

sudo rm /var/lib/dpkg/lock-frontend

sudo rm /var/lib/dpkg/lock

然后继续执行安装命令:sudo apt install mysql-server -y

3.查看mysql服务是否启动:systemctl status mysql.service

[email protected]:~/Downloads$ systemctl status mysql.service
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en
   Active: active (running) since Fri 2022-07-22 08:09:26 PDT; 7min ago
 Main PID: 9595 (mysqld)
    Tasks: 28 (limit: 1087)
   CGroup: /system.slice/mysql.service
           └─9595 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

Jul 22 08:09:26 ubuntu systemd[1]: Starting MySQL Community Server...
Jul 22 08:09:26 ubuntu systemd[1]: Started MySQL Community Server.

4.mysql安全设置:sudo mysql_secure_installation

5.登录:sudo mysql -u root -p

6.修改密码:alter user 'root'@'localhost' identified by '12345678';

7.允许root用户远程登录:grant all privileges on *.* to 'root'@'%' identified by '12345678';

8.开通防火墙端口3306:sudo ufw allow 3306

9.修改配置,允许远程连接:

cd /etc/mysql/mysql.conf.d

sudo vim mysqld.cnf

将127.0.0.1注释掉

10.重启服务:sudo systemctl restart mysql

原网站

版权声明
本文为[Three Big Stones]所创,转载请带上原文链接,感谢
https://blog.csdn.net/dandingwangzi/article/details/125941832