bannerAds
Global
language language

Product

Doc

Support

Menu 

SiliCloud Help Document Center

search

Popular search terms

Ubuntu 20.04 安装 Mysql 8.0

Update time 2023-08-11 23:00  Version v2.6
I want feedback 
Collect My collection

1.更新软件库缓存

apt update

2.使用APT安装 Mysql
Ubuntu 20 官方源提供了Mysql 8

apt install mysql-server

3.启动Mysql

systemctl start mysql.service

4.初始化密码

> mysql

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'silicloud123456';

5.初始化Mysql

> mysql_secure_installation

Securing the MySQL server deployment.

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?

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: 0
Using existing password for root.

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

 ... skipping.
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) : Yes
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) : Yes
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) : Yes
 - 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) : Yes
Success.

All done!
  1. 创建数据库和用户
CREATE USER 'user01'@'%' IDENTIFIED BY 'password01';

ALTER USER 'user01'@'%' IDENTIFIED WITH mysql_native_password BY 'password01';

GRANT PRIVILEGE ON database01 TO 'user01'@'%';

CREATE DATABASE database01;

FLUSH PRIVILEGES;
  1. 测试登录
mysql -uuser01 -p 
OUTPUT:
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.33-0ubuntu0.20.04.4 (Ubuntu)

Copyright (c) 2000, 2023, 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>

Do you have any suggestions for this document?

Your rating for this document