CentOS7.6 yum安装Mariadb

安装mariadb,并配置开机启动

安装

[root@localhost ~]# yum -y install mariadb mariadb-server			# 需要安装mariadb和mariadb两个包

启动

[root@localhost ~]# systemctl start mariadb							# 启动mariadb

设置开机自启动

[root@localhost ~]# systemctl enable mariadb						# 设置开机启动
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to
 /usr/lib/systemd/system/mariadb.service.

配置mariadb

[root@localhost ~]# 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 for none):						# 输入root密码,默认是空直接回车即可
OK, successfully used password, moving on...

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

Set root password? [Y/n] Y												# 是否设置root密码,选择“Y”设置密码
New password:															# 输入密码
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
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											# 是否移除匿名用户,选择“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”
 ... 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							# 是否移除测试数据库
 - 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@localhost ~]# mysql -u root -p
Enter password:															# 密码是上一步配置的时候设置的密码
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.65-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)]> USE mysql ;											# 切换到mysql库
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed

MariaDB [mysql]> SELECT user, host FROM user ;							# 查询当前所有用户信息,都是本地用户
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1       |
| root | localhost |
+------+-----------+
3 rows in set (0.00 sec)

MariaDB [mysql]> CREATE USER 'root'@'%' IDENTIFIED BY '123456' ;		# 创建root账号%是远程登录的意识,密码是123456
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION ;		# 给远程账户授权
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> FLUSH PRIVILEGES ;										# 刷新权限表使授权生效
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> exit													# 退出,用工具进行远程登录
Bye

测试连接

在这里插入图片描述

如果是云主机还需要配置规则
以阿里云为例
进入控制台—网络与安全—配置规则—手动添加—输入如下图所示保存即可
在这里插入图片描述
在这里插入图片描述
连接如下:成功连上
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爬坡的蜗牛

你的鼓里是我创造最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值