01 CentOS7.6 yum安装Mariadb

01 CentOS7.6 yum安装Mariadb

  • 安装mariadb,并配置开机启动
    • 安装
    • 启动
    • 设置开机自启动
  • 配置mariadb
  • 创建远程登录的root账号
    • 创建远程登录账号
    • 测试连接

安装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

测试连接

01 CentOS7.6 yum安装Mariadb_第1张图片

如果是云主机还需要配置规则
以阿里云为例
进入控制台—网络与安全—配置规则—手动添加—输入如下图所示保存即可
01 CentOS7.6 yum安装Mariadb_第2张图片
01 CentOS7.6 yum安装Mariadb_第3张图片
连接如下:成功连上
01 CentOS7.6 yum安装Mariadb_第4张图片

你可能感兴趣的:(104,MySQL,学习笔记)