甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,所以社区采用分支的方式来避开这个风险。 过去一年中,大型互联网用户以及Linux发行商纷纷抛弃MySQL,转投MariaDB阵营。MariaDB是目前最受关注的MySQL数据库衍生版,也被视为开源数据库MySQL的替代品。php
[root@test01 ~]# cd /usr/local/src [root@test01 src]# wget http://mirrors.neusoft.edu.cn/mariadb//mariadb-10.3.12/bintar-linux-x86_64/mariadb-10.3.12-linux-x86_64.tar.gz
[root@test01 src]# tar -zxvf mariadb-10.3.12-linux-x86_64.tar.gz [root@test01 src]# ls mariadb-10.3.12-linux-x86_64 mariadb-10.3.12-linux-x86_64.tar.gz [root@test01 src]# mv mariadb-10.3.12-linux-x86_64 /usr/local/mysql [root@test01 src]# ls /usr/local/mysql/ bin COPYING COPYING.thirdparty CREDITS data docs EXCEPTIONS-CLIENT include INSTALL-BINARY lib man mysql-test README.md README-wsrep scripts share sql-bench support-files
[root@test01 src]# mkdir -p /data/mysql #为MariaDB建立目录 [root@test01 src]# useradd -M -s /sbin/nologin mysql #为MariaDB建立用户
上面所示的useradd -M 表示不为该用户建立家目录,-s是指定shell的,后面的nologin表示是系统用户,不能进行登陆操做。mysql
[root@test01 mysql]# ./scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql Installing MariaDB/MySQL system tables in '/data/mysql/' ... ./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
[root@test01 mysql]# yum install libaio libaio-devel -y [root@test01 mysql]# ./scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql [root@test01 mysql]# echo $? 0
[root@test01 support-files]# cp mysql.server /etc/init.d/mysqld [root@test01 support-files]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql datadir=/data/mysql
[root@test01 ~]# chkconfig --add mysqld [root@test01 ~]# chkconfig --list Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'. To see services enabled on particular target use 'systemctl list-dependencies [target]'. agentwatch 0:off 1:off 2:on 3:on 4:on 5:on 6:off mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[mysqld] datadir=/data/mysql 须要修改的地方 socket=/tmp/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=/data/mysql/mariadb.log 须要修改的地方 pid-file=/data/mysql/mariadb.pid 须要修改的地方 # # include all files from the config directory # !includedir /etc/my.cnf.d
[root@test01 ~]# ps aux | grep mysql root 2433 0.0 0.1 112708 980 pts/0 S+ 13:23 0:00 grep --color=auto mysql 这个状态是没启动的 [root@test01 ~]# service mysql start Starting MariaDB.190209 13:28:36 mysqld_safe Logging to '/data/mysql/mariadb.log'. 190209 13:28:36 mysqld_safe Starting mysqld daemon with databases from /data/mysql [ OK ] [root@test01 ~]# ps aux | grep mysql root 2782 0.0 0.3 11816 1640 pts/0 S 13:28 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/test01.pid mysql 2870 1.3 14.7 1255904 73784 pts/0 Sl 13:28 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mariadb.log --pid-file=/data/mysql/test01.pid --socket=/tmp/mysql.sock root 2911 0.0 0.1 112708 980 pts/0 R+ 13:28 0:00 grep --color=auto mysql 这个状态是启动的状态
[root@test01 ~]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3067/sshd tcp6 0 0 :::3306 :::* LISTEN 2870/mysqld
[root@test01 ~]# /usr/local/mysql/bin/mysql -uroot 使用root来链接 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 9 Server version: 10.3.12-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.
[root@test01 bin]# ln -s /usr/local/mysql/bin/mysql /usr/bin/ 软连接的作式 [root@test01 bin]# alias mysql='/usr/local/mysql/bin/mysql' 作别名的方式、 [root@test01 ~]# PATH=$PATH:/usr/local/mysql/bin/ 更改环境变量(临时生效,换终端不生效) 更改/etc/profile 文件,在最后添加一行export PATH=$PATH:/usr/local/mysql/bin 永久生效。
[root@test01 ~]# mysqladmin -uroot password "mysqlpasscode" 设定密码 [root@test01 ~]# mysql -uroot -pmysqlpasscode 使用密码链接。