MySQL

云计算大神-带你安装MySQL数据库并去除安全隐患

2021-07-31  本文已影响0人  学神来啦

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 MySQLSERVERS IN PRODUCTION USE!PLEASE READ EACH STEP CAREFULLY!In order to log into MySQL to secure it,we'll need the currentpasswordforthe root user.If you've just installed MySQL,andyou haven't set the root password yet,the password will be blank,so you should just press enter here.Enter current passwordforroot(enterfornone):#初次运行直接回车,因为root用户没有密码OK,successfully used password,moving on…Setting the root password ensures that nobody can log into the MySQLroot user without the proper authorisation.Set root password?[Y/n]Y #是否设置root用户密码,输入YNew password:123456#新密码123456Re-enter new password:123456Password updated successfully!。。。Remove anonymous users?[Y/n]Y #是否删除匿名用户,生产环境建议删除,所以直接回车或 Y...Success!Normally,root should only be allowed to connect from'localhost'.Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely?[Y/n]Y #是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止...Success!Bydefault,MariaDB comes with a database named'test'that anyone canaccess.This is also intended onlyfortesting,and should be removedbefore 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 farwill 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 MariaDBinstallation should now be secure.Thanksforusing 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|+-------------------------+3rows

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

4. 测试网站是否支持PHP

[root@xuegod63~]# cd/var/www/html/

[root@xuegod63 html]# vim index.php<?phpphpinfo();?>

[root@xuegod63 html]# systemctl restart httpd #重启httpd服务。

[root@xuegod63 html]# iptables-F #清空防火墙

测试:

http://192.168.1.63/index.php

LAMP网站架构搭建完成

到此MySQL数据库安装成功

上一篇下一篇

猜你喜欢

热点阅读