Home  >  Article  >  Database  >  How to install MySQL in Ubuntu18.04

How to install MySQL in Ubuntu18.04

醉折花枝作酒筹
醉折花枝作酒筹forward
2021-05-26 09:07:322706browse

This article will introduce to you how to install MySQL in Ubuntu 18.04. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

How to install MySQL in Ubuntu18.04

Ubuntu18.04 Install MySQL

Environment information:

OS: Ubuntu18.04

MySQL: 5.7. 22

1. Install MySQL

In Ubuntu, by default, only the latest version of MySQL is included in APTIn the package repository, to install it, just update the package index on the server and install the default package apt-get.

#命令1
sudo apt-get update
#命令2
sudo apt-get install mysql-server

How to install MySQL in Ubuntu18.04

2. Configure MySQL

2.1 Initial configuration

sudo mysql_secure_installation

There are many configuration items, as shown below:

#1
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N (我的选项)

#2
Please set the password for root here...
New password: (输入密码)
Re-enter new password: (重复输入)

#3
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...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的选项)

#4
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 (我的选项)

#5
By default, MySQL comes with a database named 'test' that
anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的选项)

#6
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 (我的选项)

2.2 Check the mysql service status

systemctl status mysql.service

The following results show that the mysql service is normal:

How to install MySQL in Ubuntu18.04

##3. Configure remote access

Under Ubuntu, MySQL only allows local access by default, and cannot be connected using the workbench connection tool;

If you want other machines to be able to access it, you need to configure it;

3.1 First, use the root user to enter

sudo mysql -uroot -p

to log in to root to make other settings:

How to install MySQL in Ubuntu18.04

GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "123456";

How to install MySQL in Ubuntu18.04

root@localhos , localhost means local access. If configured as %, all hosts can connect;

The second

'123456' is The password you set for the new user with new permissions, % represents all hosts, or it can be a specific IP;

However, this is set with

%, but my root pass The tool still cannot be logged in, maybe for security reasons, so create a new database and user;

3.2 Create a new database and user

Use the root user to create new data and a user for remote access

##1 创建数据库weixx
CREATE DATABASE weixx;
##2 创建用户wxx(密码654321) 并允许wxx用户可以从任意机器上登入mysql的weixx数据库
GRANT ALL PRIVILEGES ON weixx.* TO wxx@"%" IDENTIFIED BY "654321";

4. Use workbench to connect to the database

Open workbench for connection configuration:

How to install MySQL in Ubuntu18.04

After the configuration is completed, select the weixx database in the main interface to connect:

How to install MySQL in Ubuntu18.04

Related recommendations: "

mysql tutorial"

The above is the detailed content of How to install MySQL in Ubuntu18.04. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete