分享技术,记录生活,在互联网上留下属于自己的一亩三分地。

Ubuntu18.04安装Mysql

数据库 novadmin 214℃ 0评论

1、Ubuntu18.04安装Mysql


zhj@zhj-machine:~$ sudo apt-get install mysql-server

2、修改安全配置:


zhj@zhj-machine:~$ sudo 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: y                               //这里是询问是否检查root密码的安全策略,如果检查输入“y”,这里选择“y”

There are three levels of password validation policy:

LOW    Length >= 8   //表示密码安全级别代表低
MEDIUM Length >= 8, numeric, mixed case, and special characters       //表示数字+大小写+特殊字符共3种
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file  //表示数字+大小写+特殊字符+字典共4种

(因为我这是实验环境,这里我选择0,生成环境建议选择1或者2,保证数据库的安全)
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0    //根据实际情况选择安全策略:0表示低策略;1表示密码安全级别为中等;2表示强壮密码,安全级别最优。
Please set the password for root here.

New password:                                        //输入密码,是不显示的直接输入即可

Re-enter new password:                              //重复输入密码

Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y              //是否还需要继续下面的安全设置,这里选择“y”
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       //是否移除除了root以外的其他用户,默认会有个测试用户,这里我们需要删除测试用户,选择“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     //是否允许数据库root用户远程登录,这里根据实际情况选择“y”还是“n”,这里我选择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 //是否移除测试数据库,默认安装完mysql,会有test数据库是测试的,可以删除,选择“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   //刷新数据库,刚才的配置,选择“y”
Success.

All done! 
zhj@zhj-machine:~$ 

3、使用密码登录数据库

zhj@zhj-machine:~$ sudo mysql -uroot -p
[sudo] zhj 的密码:                                     //这里是用户zhj的密码
Enter password:                                         //这里才是数据库的密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.7.26-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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> 

从信息可以看到,数据库版本是5.7.26

4、数据库的配置文件是:my.cnf


zhj@zhj-machine:~$ more /etc/mysql/my.cnf
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

转载请注明:Nov » Ubuntu18.04安装Mysql

喜欢 (0)or分享 (0)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址