甲骨文公司收購了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 使用密碼鏈接。