本文转自:https://www.sohu.com/a/480652500_121168443
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
LAMP网站架构搭建完成
到此MySQL数据库安装成功
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
【MySQL 30周年庆】MySQL 8.0 OCP考试限时免费!教你免费领考券
墨天轮小教习
513次阅读
2025-04-25 18:53:11
墨天轮个人数说知识点合集
JiekeXu
447次阅读
2025-04-01 15:56:03
MySQL 30 周年庆!MySQL 8.4 认证免费考!这次是认真的。。。
严少安
431次阅读
2025-04-25 15:30:58
MySQL数据库当前和历史事务分析
听见风的声音
427次阅读
2025-04-01 08:47:17
MySQL 生产实践-Update 二级索引导致的性能问题排查
chengang
391次阅读
2025-03-28 16:28:31
【活动】分享你的压箱底干货文档,三篇解锁进阶奖励!
墨天轮编辑部
365次阅读
2025-04-17 17:02:24
MySQL 9.3 正式 GA,我却大失所望,新特性亮点与隐忧并存?
JiekeXu
357次阅读
2025-04-15 23:49:58
3月“墨力原创作者计划”获奖名单公布
墨天轮编辑部
332次阅读
2025-04-15 14:48:05
openHalo问世,全球首款基于PostgreSQL兼容MySQL协议的国产开源数据库
严少安
305次阅读
2025-04-07 12:14:29
记录MySQL数据库的一些奇怪的迁移需求!
陈举超
201次阅读
2025-04-15 15:27:53