CentOS 7 安装 MariaDB
1. 阿里云源下载安装 MariaDB
yum install mariadb-server mariadb -y
2. 使用 systemctl 管理 MariaDB 服务
systemctl start mariadb # 启动MariaDB
systemctl stop mariadb # 停止MariaDB
systemctl restart mariadb # 重启MariaDB
systemctl enable mariadb # 设置开机启动
3. 初始化 MariaDB
mysql_secure_installation
4. 进入MariaDB 数据库
[root@localhost ~]# mysql -uroot -p
Enter password:
5. 创建数据库用户
MariaDB [(none)]> create user rpw@'127.0.0.1' identified by 'admin'; Query OK, 0 rows affected (0.04 sec) MariaDB [(none)]> use mysql Database changed MariaDB [mysql]> select host,user,password from user; +-----------------------+-------+-------------------------------------------+ | host | user | password | +-----------------------+-------+-------------------------------------------+ | localhost | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | | localhost.localdomain | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | | 127.0.0.1 | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | | ::1 | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | | 127.0.0.1 | rpw | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | +-----------------------+-------+-------------------------------------------+ 5 rows in set (0.00 sec) MariaDB [mysql]>
6. 数据库权限设置
MariaDB [(none)]> use mysql; Database changed MariaDB [mysql]> grant all privileges on *.* to rpw@127.0.0.1; Query OK, 0 rows affected (0.00 sec) MariaDB [mysql]> show grants for rpw@127.0.0.1; +---------------------------------------------------------------------------------------------------------------------+ | Grants for rpw@127.0.0.1 | +---------------------------------------------------------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'rpw'@'127.0.0.1' IDENTIFIED BY PASSWORD '*4ACFE3202A5FF5CF467898FC58AAB1D615029441' | +---------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) MariaDB [mysql]>
# 刷新权限
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
7. 移除权限
MariaDB [mysql]> revoke all privileges on *.* from rpw@127.0.0.1; Query OK, 0 rows affected (0.00 sec) MariaDB [mysql]>
8. 中文编码设置,编辑 /etc/my.cnf 文件,添加以下内容
[mysqld] character-set-server=utf8 collation-server=utf8_general_ci log-error=/var/log/mysqld.log [client] default-character-set=utf8 [mysql] default-character-set=utf8