【MySQL】Ubuntu22.04 安装 MySQL8 数据库详解 [复制链接]
发表于 2026-2-13 01:37:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
🔥博客主页: 小羊失眠啦.
🎥系列专栏:《C语言》 《数据布局》 《C++》 《Linux》《MySQL》《Qt》
❤️感谢各人点赞👍收藏⭐批评✍️
  

一、安装目次

1.1 更新软件源

  1. sheep@Aron:/root$ sudo apt update
复制代码
1.2 安装mysql_server

  1. sheep@Aron:/root$ sudo apt install mysql-server
复制代码
1.3 安装libmysqlclient-dev

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

二、设置MySQL

2.1 进入MySQL

  1. sheep@Aron:/root$ mysql -uroot -pWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 20Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
复制代码
2.2 修改暗码

实行以下下令,然后运行以下 ALTER USER 下令将 root 用户的身份验证方法更改为利用暗码的方法。 以下示例将身份验证方法更改为 mysql_native_password
  1. 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

  1. mysql> exitByesheep@Aron:/root$
复制代码
2.4 以sudo权限运行mysql_secure_installation

  1. sheep@Aron:/root$ sudo mysql_secure_installationSecuring the MySQL server deployment.# 输入暗码passwordEnter password for user root:
复制代码
2.5 设置暗码计谋和暗码

  1. sheep@Aron:/root$ sudo mysql_secure_installationSecuring the MySQL server deployment.# 输入暗码passwordEnter password for user root: VALIDATE PASSWORD COMPONENT can be used to test passwordsand improve security. It checks the strength of passwordand allows the users to set only those passwords which aresecure enough. Would you like to setup VALIDATE PASSWORD component?# 输入YPress y|Y for Yes, any other key for No: YThere are three levels of password validation policy:LOW    Length >= 8MEDIUM Length >= 8, numeric, mixed case, and special charactersSTRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file# 输入0Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0Using existing password for root.# 输入YEstimated strength of the password: 50 Change the password for root ? ((Press y|Y for Yes, any other key for No) : # 输入暗码12345678New password: # 输入暗码12345678Re-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) : YBy default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to havea user account created for them. This is intended only fortesting, and to make the installation go a bit smoother.You should remove them before moving into a productionenvironment.
复制代码
2.6 其他设置

  1. # 输入NRemove 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 atthe root password from the network.# 输入YDisallow root login remotely? (Press y|Y for Yes, any other key for No) : YSuccess.By default, MySQL comes with a database named 'test' thatanyone can access. This is also intended only for testing,and should be removed before moving into a productionenvironment.# 输入NRemove 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 changesmade so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : YSuccess.All done!
复制代码

三、 检察MySQL

表现active表现已经在运行
  1. 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/mysqldJul 18 15:19:38 Aron systemd[1]: Starting MySQL Community Server...Jul 18 15:19:39 Aron systemd[1]: Started MySQL Community Server.
复制代码
四、登录MySQL数据库

  1. sheep@Aron:/root$ mysql -uroot -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 21Server 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!qidao123.com:ToB企服之家,中国第一个企服评测及软件市场,开放入驻,技术点评得现金
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表