Install MySql database under Ubutnu 18.04

Recently, I am working on a Django-related agricultural bank project and need to deploy a test environment. Here, I will record it again. Under Ubuntu 18, install each software and its Djano-related deployment process.

Let me talk about the installation of MySql. Here I use Ubuntu 18. The installation method is as follows.

apt install mysql-server

After the installation is complete, the system will start the Mysql service by default

After the installation is complete, use the following command to log in

mysql -u root -p

 -u means select the login user, -p means the password of the login user, there is no password for initial installation, just press Enter to enter the database.

 Then pass

show databases; 

You can view all current databases.

 

 Next, we need to initialize the database.

Enter on the Ubuntu command line:

mysql_secure_installation
root@ip-172-31-23-232:/home/ubuntu# mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN 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 plugin? # 要安装验证密码插件吗?

Press y|Y for Yes, any other key for No: N
Please set the password for root here.

New password: # 输入要为root管理员设置的数据库密码

Re-enter new password:  # 再次输入密码
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) : N  # 禁止root管理员从远程登录,这里我没有禁止

 ... skipping.
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) : U^HY   # 删除test数据库并取消对它的访问权限

 ... skipping.
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! 

Enter the mysql command line again, here you can log in using the password just now.

 After that, we configure mysql remote login access.

Edit configuration file

vim /etc/mysql/mysql.conf.d/mysqld.cnf

Find the position as shown in the figure below and modify

Comment it out. Save and exit.

mysql -u root -p

Enter the mysql command line

mysql> grant all on *.* to root@'%' identified by '你的密码' with grant option;

Refresh permissions

mysql> flush privileges;    # 刷新权限

drop out

mysql> exit

Execute the following command to restart mysql

systemctl restart mysql

Now you can directly access myql remotely.

If remote access is still not possible, please check the security group settings of the server to see if the corresponding port is opened.

At this point, the installation of mysql service on Ubuntu 18 has been completed. thanks for reading. Thanks for the praise and communication. Thank you

 

 

Guess you like

Origin blog.csdn.net/u012798683/article/details/107312809