云计算架构师-带你安装MySQL数据库并去除安全隐患

Mariabd安全配置向导

1.安装完mariadb-server后,运行mysql_secure_installation去除安全隐患
mysql_secure_installation会执行几个设置:

  • 为root用户设置密码
  • 删除匿名账号
  • 取消root用户远程登录
  • 删除test库和对test库的访问权限
  • 刷新授权表使修改生效
[root@xuegod63 ~]# mysql_secure_installation #进入安全配置向导

 

通过这几项的设置能够提高MySQL库的安全。建议生产环境中MySQL安装完成后一定要运
行一次mysql_secure_installation,详细步骤请参看下面的命令:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): #初次运行直接回车,因为root用户没有密码
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] Y #是否设置root用户密码,输入Y
New password: 123456 #新密码123456
Re-enter new password: 123456
Password updated successfully!
。。。
Remove anonymous users? [Y/n] Y #是否删除匿名用户,生产环境建议删除,所以直接回车或 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? [Y/n] Y #是否禁止root远程登录,根据自己的需求选择
Y/n并回车,建议禁止
... Success!
By default, MariaDB 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? [Y/n] Y #是否删除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? [Y/n] Y #是否重新加载权限表,直接回车
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!

 

如果不做安全配置,设置root密码

[root@xuegod63 ~]# mysqladmin -u root password "123456"

 

2. 数据库连接

连接MariaDB数据库,连接本机可以去掉 -h选项

# mysql #如MariaDB没有设置密码,并在本地上登录,而且是使用默认端口的情况
下,可以直接使用mysql命令登录。
或:
# mysql -h IP -u USER -pPASS #如 MariaDB不是安装在本地时,需要使用-h选项指定
IP登录,如 MariaDB用户设置了密码时,需要使用-u选项指定用户,并使用-p选项指定密码,注意的是
在-p选项和密码之间不能有空格,否则在命令执行后需要再次输入密码,并将有空格的密码串识别为登录
的数据库。
MariaDB的超级管理员是root用户,拥有MariaDB数据库的最高权限。

3. 测试数据是否正常

[root@xuegod63 ~]# mysql -u root -p123456 
MariaDB [(none)]> show databases; #没有test数据库 #执行时,所有命令以;号结尾
+-------------------------+ 
| Database | 
+-------------------------+ 
| information_schema | 
| mysql | 
| ucenter |
+-------------------------+ 
3 rows in set (0.00 sec) 

 


MariaDB [(none)]> exit #退出命令可以加分号,也可以不加分号。

4. 测试网站是否支持PHP

[root@xuegod63 ~]# cd /var/www/html/
[root@xuegod63 html]# vim index.php 
<?php 
phpinfo(); 
?> 
[root@xuegod63 html]# systemctl restart httpd #重启httpd服务。
[root@xuegod63 html]# iptables -F #清空防火墙

 

测试:

http://192.168.1.63/index.php
云计算架构师-带你安装MySQL数据库并去除安全隐患
LAMP网站架构搭建完成

到此MySQL数据库安装成功

                                    小伙伴想要获取学习视频+笔记资料的
                                           请添加我们小姐姐
                                    我们也有Windows上安装mysql教程哦!
云计算架构师-带你安装MySQL数据库并去除安全隐患
上一篇:Linux Mysql(Mariadb)


下一篇:linux安装MariaDB