Ubuntu23.10如何安装Mysql8

MySQL是一个开源、快速可靠、灵活的关系数据库管理系统,通常与PHP一起使用。在本文中,我们将学习如何在Ubuntu 22.04上安装MySQL 8。所以,让我们开始吧。

准备:

  • 安装并运行Ubuntu 23.10的系统。
  • root或sudo用户对系统的访问权限。

一、安装Mysql8

使用以下命令安装MySQL 8

apt update

apt -y install mysql-server

接下来, 是用以下命令安装Mysql8 安全配置

mysql_secure_installation

输出以下内容

root@ubuntu23:~# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

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?

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

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2

Skipping password set for root as authentication with auth_socket is used by default.
If you would like to use password authentication instead, this can be done with the "ALTER_USER" command.
See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user-password-management for more information.

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.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.

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

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.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

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!

检查数据库服务器状态。

systemctl status mysql

二、创建数据库

Mysql8 安装好之后,需要创建用户,并且授予权限,能够和数据库进行交互

mysql

CREATE USER 'test_user'@'localhost' IDENTIFIED BY "Password";

CREATE DATABASE test_db;

GRANT ALL PRIVILEGES ON test_db.* TO 'test_user'@'localhost';

FLUSH PRIVILEGES;

EXIT

使用以下命令检查版本和新创建的数据库,

root@ubuntu23:~# mysql -V
mysql  Ver 8.0.34-1ubuntu1 for Linux on x86_64 ((Ubuntu))

现在,您可以使用以下命令连接到MySQL并查看数据库服务器上的现有数据库。

mysql -e "SHOW DATABASES;" -p

原创文章,作者:zhuji001,如若转载,请注明出处:https://www.zhuji66.com/ubuntu23-install-mysql8/

本站分享VPS和云服务器信息均来源于网络,如有侵权请邮箱联系zhuji66com@yeah.net。本站不销售任何产品,如遇问题请联系对应客服。