侧边栏壁纸
博主头像
一揽芳华 博主等级

行动起来,活在当下

  • 累计撰写 265 篇文章
  • 累计创建 24 个标签
  • 累计收到 4 条评论

目 录CONTENT

文章目录

13.2、安装初始化mariadb数据库系统

芳华是个男孩!
2024-10-14 / 0 评论 / 0 点赞 / 7 阅读 / 0 字
广告 广告

title: 02-安装数据库
order: 2

icon: lightbulb

实例1、安装初始化mariadb数据库系统,并配置允许使用root账户远程连接

1、检查yum源环境

[root@host-172-16-0-4 ~]# yum clean all && yum repolist

2、安装mariadb数据库系统

[root@host-172-16-0-4 ~]# yum install mariadb* -y

3、重启mariadb数据库系统,并设置开机自启

[root@host-172-16-0-4 ~]# systemctl restart mariadb && systemctl enable mariadb

4、初始化mariadb数据库系统

[root@host-172-16-0-4 ~]# mysql\_secure\_installation

编辑配置如下图所示:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, 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

OK, successfully used password, moving

Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation.

Set root password? [Y/n] y //输入y

New password: //输入root管理员密码

Re-enter new password: //再次输入密码

Password updated successfully!

Reloading privilege tables..

... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for

//当前数据库密码为空,默认回车

for none): on...

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] 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管理员从远程登录

... 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数据库并取消对它的权限访

问

- 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!

5、防火墙放行数据库服务,并重启防火墙

[root@host-172-16-0-4 ~]# firewall-cmd --permanent --add-service=mysql [root@host-172-16-0-4 ~]# firewall-cmd --reload

6、首次登录数据库系统

[root@host-172-16-0-4 ~]# mysql -u root -p

Enter password: //输入root管理员用户密码

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 10

Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

7、配置允许root用户远程登录

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '0000'

WITH GRANT OPTION; //'root'为root用户, '0000'为root用户密码

8、刷新生效

MariaDB [(none)]> flush privileges;

9、使用软件Navicat for MySQL进行登录

10、连接测试

11、双击测试中的mysql激活

12、打开命令行窗口并查看当前数据库中有哪些数据库

说明配置root用户远程登录的另一种方法就是,在初始化过程中,我们将是否不允许root用户远程登录 yes或no ,选择no ,如图所示:

0
广告 广告

评论区