话不多说,直接搞起!
1. 安装主程序和服务端
yum install -y mariadb mariadb-server
2. 启动和查看Mariadb数据库
systemctl start mariadb # 启动
systemctl status mariadb # 查看运行状态 active(running) 代表已经运行
3. 加入开机启动项
systemctl enable mariadb
4. 对mariadb进行初始化操作
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] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
Password updated successfully!
Reloading privilege tables..
… Success!
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? [Y/n] <– 是否删除匿名用户,生产环境建议删除,所以直接回车
… 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] <–是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止(后续需要开启可重新执行命令选择n)
… 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? [Y/n] <– 是否删除test数据库,直接回车
- 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] <– 是否重新加载权限表,直接回车
… Success!
Cleaning up…
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
5.修改字符串编码为utf8,防止乱码
在MariaDB的配置文件/etc/my.cnf中加入以下两句配置
vim /etc/my.cnf
将下面两行 复制到文本中
character_set_server=utf8
init_connect='SET NAMES uft8'
保存退出后,重新启动mariadb
systemctl restart mariadb
6.登陆mysql
mysql -u root -p
# 创建数据库
# 创建普通用户
GRANT ALL ON 数据库名.* TO '用户名'@'IP地址主机' DENTIFIED BY '配置用户密码'; # 将这个数据库的所有权限赋予给这个用户
7. 防火墙开启端口,放行
firewall-cmd --list-port # 查看目前开放的端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent 方式一
firewall-cmd --zone=public --add-service=mysql --permanent 方式二
firewall-cmd --reload 重载配置生效
8. 开启root远程访问权限
mysql -uroot -p
select User, host from mysql.user;
root账户中的host项是localhost表示该账号只能进行本地登录,我们需要修改权限,输入命令:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '设置密码' WITH GRANT OPTION;
修改权限。%表示针对所有IP,password表示将用这个密码登录root用户,如果想只让某个IP段的主机连接,可以修改为
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.100.%' IDENTIFIED BY '设置密码' WITH GRANT OPTION;
注意:此时远程连接的密码可能与你在本地登录时的密码不同了,主要看你在IDENTIFIED BY后面给了什么密码\
FLUSH PRIVILEGES;
_____ _ _____ _
/ ____| (_) / ____| | |
| | __ _ _ | | | |__ ___ _ __
| | / _` | | | | | | '_ \ / _ \ | '_ \
| |____ | (_| | | | | |____ | | | | | __/ | | | |
\_____| \__,_| |_| \_____| |_| |_| \___| |_| |_|
好了各位,以上就是这篇文章的全部内容了,能看到这里人啊,都是人才。
如果这个文章写得还不错,觉得「王采臣」我有点东西的话 求点赞👍求关注❤️求分享👥 对耿男我来说真的非常有用!!!
白嫖不好,创作不易,各位的支持和认可,就是我创作的最大动力,我们下篇文章见!
王采臣 | 文 【原创】 如果本篇博客有任何错误,请批评指教,不胜感激 !微信公众号: