【MySQL】Ubuntu22.04 安装 MySQL8 数据库详解

🔥博客主页小羊失眠啦.
🎥 系列专栏《C语言》 《数据结构》 《C++》 《Linux》《MySQL》《Qt》

❤️感谢大家点赞👍收藏⭐评论✍️


一、安装目录

1.1 更新软件源

bash 复制代码
sheep@Aron:/root$ sudo apt update

1.2 安装mysql_server

bash 复制代码
sheep@Aron:/root$ sudo apt install mysql-server

1.3 安装libmysqlclient-dev

bash 复制代码
sheep@Aron:/root$ sudo apt install libmysqlclient-dev

二、配置MySQL

2.1 进入MySQL

bash 复制代码
sheep@Aron:/root$ mysql -uroot -p
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 8.0.37-0ubuntu0.22.04.3 (Ubuntu)

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

2.2 修改密码

执行以下命令,然后运行以下 ALTER USER 命令将 root 用户的身份验证方法更改为使用密码的方法。 以下示例将身份验证方法更改为 mysql_native_password

bash 复制代码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '12345678';

Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;

2.3 退出MySQL

bash 复制代码
mysql> exit
Bye
sheep@Aron:/root$

2.4 以sudo权限运行mysql_secure_installation

bash 复制代码
sheep@Aron:/root$ sudo mysql_secure_installation

Securing the MySQL server deployment.

# 输入密码password
Enter password for user root: 

2.5 设置密码策略和密码

bash 复制代码
sheep@Aron:/root$ sudo mysql_secure_installation

Securing the MySQL server deployment.

# 输入密码password
Enter password for user root: 

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

# 输入Y
Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

# 输入0
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Using existing password for root.

# 输入Y
Estimated strength of the password: 50 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : 


# 输入密码12345678
New password: 

# 输入密码12345678
Re-enter new password: 

Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

2.6 其他设置

bash 复制代码
# 输入N
Remove anonymous users? (Press y|Y for Yes, any other key for No) : N

 ... skipping.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

# 输入Y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


# 输入N
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N

 ... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done! 

三、 查看MySQL

显示active表示已经在运行

bash 复制代码
sheep@Aron:/root$ sudo systemctl status mysql.service
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2024-07-18 15:19:39 CST; 4h 14min ago
   Main PID: 5806 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 1891)
     Memory: 362.0M
        CPU: 1min 4.121s
     CGroup: /system.slice/mysql.service
             └─5806 /usr/sbin/mysqld

Jul 18 15:19:38 Aron systemd[1]: Starting MySQL Community Server...
Jul 18 15:19:39 Aron systemd[1]: Started MySQL Community Server.

四、登录MySQL数据库

bash 复制代码
sheep@Aron:/root$ mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 8.0.37-0ubuntu0.22.04.3 (Ubuntu)

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
相关推荐
青草地溪水旁15 分钟前
mysql_use_result的概念和使用案例
数据库·mysql
cqths24 分钟前
.NET 9.0 的 Blazor Web App 项目、Bootstrap Blazor 组件库、自定义日志 TLog 使用备忘
数据库·c#·.net·web app
翻晒时光1 小时前
MySQL 8.0 备份与恢复全解析
mysql
程序研1 小时前
mysql之group by语句
数据库·mysql
HaoHao_0103 小时前
AWS Outposts
大数据·服务器·数据库·aws·云服务器
HaoHao_0103 小时前
VMware 的 AWS
大数据·服务器·数据库·云计算·aws·云服务器
娶个名字趴3 小时前
Redis(5,jedis和spring)
数据库·redis·缓存
ThisIsClark3 小时前
【后端面试总结】mysql的join,left join,right join,full join分别是什么意思
mysql·面试·职场和发展
小光学长3 小时前
基于vue框架的的信用社业务管理系统设计与实现4gnx5(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
数据库
鲁班班3 小时前
MySQL通过binlog恢复数据
数据库·mysql