本文主要是介绍安装mariadb并且指定数据存放目录(centos7),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、安装mariadb
[root@iZ23k27 ~]# yum -y install mariadb mariadb-server
2、启动mariadb
[root@iZ23k27 ~]# systemctl start mariadb
3、查看mariadb状态
[root@iZ23k27 ~]# systemctl status mariadb
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2019-06-03 20:17:40 CST; 27s ago
Process: 3927 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 3846 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 3926 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─3926 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─4088 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/ma...
4、关闭mariadb
[root@iZ23k27 ~]# systemctl stop mariadb
5、创建数据文件目录
[root@iZ23k27 ~]# mkdir /data/mysql_data
5、给数据文件赋权限
[root@iZ23k27 ~]# chown -R mysql:mysql /data/mysql_data
[root@iZ23k27 ~]# ls -l /var/lib/mysql
total 28704
-rw-rw---- 1 mysql mysql 16384 Jun 3 20:18 aria_log.00000001
-rw-rw---- 1 mysql mysql 52 Jun 3 20:18 aria_log_control
-rw-rw---- 1 mysql mysql 18874368 Jun 3 20:18 ibdata1
-rw-rw---- 1 mysql mysql 5242880 Jun 3 20:18 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 Jun 3 20:17 ib_logfile1
drwx------ 2 mysql mysql 4096 Jun 3 20:17 mysql
drwx------ 2 mysql mysql 4096 Jun 3 20:17 performance_schema
drwx------ 2 mysql mysql 4096 Jun 3 20:17 test
6、复制/var/lib/mysqll至数据文件目录
[root@iZ23k27 ~]# cp -a /var/lib/mysql /data/mysql_data
7、修改配置文件
[root@iZ23k27 ~]# cat /etc/my.cnf
[mysqld]
datadir=/data/mysql_data/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
lower_case_table_names=1
max_allowed_packet=30M
slow_query_log=on
slow_query_log_file=/data/mysql_data/slow_query_log.log
long_query_time=2
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
[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
8、其他按照正常流程即可,设置密码,设置远程登录权限
执行:mysql_secure_installation 配置root密码
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
参考:https://www.cnblogs.com/ld1977/p/7264485.html
https://www.linuxidc.com/Linux/2016-03/128880.htm
这篇关于安装mariadb并且指定数据存放目录(centos7)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!