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.
Environment information:
OS: Ubuntu18.04
MySQL: 5.7. 22
In Ubuntu
, by default, only the latest version of MySQL
is included in APT
In 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
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 (我的选项)
systemctl status mysql.service
The following results show that the mysql service is normal:
##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 entersudo mysql -uroot -p
GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "123456";
root@localhos ,
localhost means local access. If configured as
%, all hosts can connect;
'123456' is The password you set for the new user with new permissions,
% represents all hosts, or it can be a specific IP;
%, but my root pass The tool still cannot be logged in, maybe for security reasons, so create a new database and user;
##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 databaseOpen workbench for connection configuration: After the configuration is completed, select the weixx database in the main interface to connect: 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!