1-centos7安装mariadb

about

centos.7.6 + mariadb5.5.68

说实话,由于平常都是在Linux上使用的是mysql,就没兴趣再继续琢磨怎么安装mariadb了,但老遇到同学问,我就做个笔记。

安装

1. 首先检查是否安装了mariadb,如果有可以选择卸载,也可以选择复用

[root@VM-4-10-centos mariadb]# rpm -qa | grep mariadb
mariadb-server-5.5.68-1.el7.x86_64
mariadb-libs-5.5.68-1.el7.x86_64
mariadb-5.5.68-1.el7.x86_64

这里看到是有的,你也可以直接再使用这个,也可以卸载掉,完事在使用yum安装。

# 卸载命令
[root@VM-4-10-centos mariadb]# rpm -e --nodeps mariadb-server-5.5.68-1.el7.x86_64
[root@VM-4-10-centos mariadb]# rpm -qa | grep mariadb   # 卸载完了,在过滤就没了

2. 使用yum进行安装

[root@VM-4-10-centos mariadb]# yum -y install mariadb-server mariadb-client

3. 配置my.cnf

cat  > /etc/my.cnf <<EOF
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

EOF

4. 启动mariadb了。

启动服务:systemctl start mariadb.service

停止服务:systemctl stop mariadb.service

查看服务状态:systemctl status mariadb.service

开机启动:systemctl enable mariadb

5. 账号密码设置
默认直接输入mysql就能登录进去,所以,我们要把这个空账号给它干掉,然后设置我们自己的root用户和密码。

[root@VM-4-10-centos mariadb]# mysql   # 默认有个空账号,可以让我们初次登录使用
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-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)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> use mysql;    -- 先use到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, password, host from user;   -- 看下当前可用的用户,那几个user为空的就是我们需要去掉的
+------+----------+----------------+
| user | password | host           |
+------+----------+----------------+
| root |          | localhost      |
| root |          | vm-4-10-centos |
| root |          | 127.0.0.1      |
| root |          | ::1            |
|      |          | localhost      |
|      |          | vm-4-10-centos |
+------+----------+----------------+
6 rows in set (0.00 sec)

MariaDB [mysql]> delete from user where user = '';  -- 将为空的删掉
Query OK, 2 rows affected (0.00 sec)

MariaDB [mysql]> select user, password, host from user;  -- ok,删掉了
+------+----------+----------------+
| user | password | host           |
+------+----------+----------------+
| root |          | localhost      |
| root |          | vm-4-10-centos |
| root |          | 127.0.0.1      |
| root |          | ::1            |
+------+----------+----------------+
4 rows in set (0.00 sec)

MariaDB [mysql]> -- 将与主机名相等的字段改为 "%",当用户从客户端请求登陆时,MySQL将授权表中的条目与客户端所提供的条目进行比较,包括用户的用户名,密码和主机
MariaDB [mysql]> update user set host='%' where host='vm-4-10-centos';  -- 我的主机名叫做vm-4-10-centos
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [mysql]> -- 设置root账号的密码为123
MariaDB [mysql]> update user set password=password('123') where user='root' ;
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

MariaDB [mysql]> -- 刷新
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> exit;
Bye
[root@VM-4-10-centos mariadb]# mysql -uroot -p123 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.68-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)]> 

摘自:https://blog.csdn.net/chenwiehuang/article/details/123447322

常见报错

centos7.6+mariadb

posted @ 2022-07-07 16:10  听雨危楼  阅读(947)  评论(0编辑  收藏  举报