[root@localhost ~]# find -H /etc/ | grep my.c /etc/pki/tls/certs/make-dummy-cert /etc/pki/tls/certs/renew-dummy-cert /etc/my.cnf.d /etc/my.cnf.d/mysql-clients.cnf /etc/my.cnf
[root@localhost ~]# rm -rf /etc/my.cnf /etc/my.cnf.d/
[root@localhost ~]# find -H /etc/ | grep my.c /etc/pki/tls/certs/make-dummy-cert /etc/pki/tls/certs/renew-dummy-cert
到目前爲止, 系統最小化安裝自帶的數據庫配置文件已經刪除乾淨了!
[root@localhost ~]# rpm -qa|grep mariadb-libs mariadb-libs-5.5.52-1.el7.x86_64
[root@localhost ~]# rpm -e mariadb-libs-5.5.52-1.el7.x86_64 --nodeps
[root@localhost ~]# yum -y install libaio [root@localhost ~]# yum -y install libaio-devel [root@localhost ~]# yum -y install bison [root@localhost ~]# yum -y install bison-devel [root@localhost ~]# yum -y install zlib-devel [root@localhost ~]# yum -y install openssl [root@localhost ~]# yum -y install openssl-devel [root@localhost ~]# yum -y install ncurses [root@localhost ~]# yum -y install ncurses-devel [root@localhost ~]# yum -y install libcurl-devel [root@localhost ~]# yum -y install libarchive-devel [root@localhost ~]# yum -y install boost [root@localhost ~]# yum -y install boost-devel [root@localhost ~]# yum -y install lsof [root@localhost ~]# yum -y install wget [root@localhost ~]# yum -y install gcc [root@localhost ~]# yum -y install gcc-c++ [root@localhost ~]# yum -y install make [root@localhost ~]# yum -y install cmake [root@localhost ~]# yum -y install perl [root@localhost ~]# yum -y install kernel-headers [root@localhost ~]# yum -y install kernel-devel [root@localhost ~]# yum -y install pcre-devel
[root@localhost ~]# mkdir soft [root@localhost ~]# cd soft
[root@localhost soft]# wget https://downloads.mariadb.org/interstitial/mariadb-10.2.6/source/mariadb-10.2.6.tar.gz
[root@localhost soft]# tar -zxvf mariadb-10.2.6.tar.gz
這裏提早預約MariaDB的安裝目錄爲/usr/local/mysql而且數據庫目錄爲/data/mysql,這裏要創建系統用戶及組和數據庫存放目錄,而且將數據庫存放目錄賦予mysql用戶及組權限,操做以下:請注意特別說明一下:這裏說的數據庫目錄是指的具體數據庫存儲文件, 而不是安裝文件!node
[root@localhost soft]# groupadd -r mysql
[root@localhost soft]# useradd -r -g mysql -s /sbin/nologin -d /usr/local/mysql -M mysql
如下是上面建立系統用戶mysql的各個參數說明:-r: 添加系統用戶( 這裏指將要被建立的系統用戶mysql )mysql
-g: 指定要建立的用戶所屬組( 這裏指添加到新系統用戶mysql到mysql系統用戶組 )c++
-s: 新系統賬戶的登陸shell(
/sbin/nologin
這裏設置爲將要被建立系統用戶mysql不能用來登陸系統 )sql-d: 新賬戶的主目錄( 這裏指定將要被建立的系統用戶mysql的家目錄爲
/usr/local/mysql
)shell-M: 不要建立用戶的主目錄( 也就是說將要被建立的系統用戶mysql不會在
/home
目錄下建立mysql
家目錄 )數據庫
[root@localhost soft]# mkdir -p /usr/local/mysql
[root@localhost soft]# mkdir -p /data/mysql
[root@localhost soft]# chown -R mysql:mysql /data/mysql
> 進入到解壓後的源碼包文件夾 [root@localhost soft]# cd mariadb-10.2.6 > 輸入編譯參數 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/data/mysql \ -DSYSCONFDIR=/etc \ -DWITHOUT_TOKUDB=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STPRAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWIYH_READLINE=1 \ -DWIYH_SSL=system \ -DVITH_ZLIB=system \ -DWITH_LOBWRAP=0 \ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci > 若是編譯失敗請刪除CMakeCache.txt [root@localhost soft]# rm -f CMakeCache.txt > 讓指令從新執行,不然每次讀取這個文件,命令修改正確也是報錯 > cmake沒問題,能夠編譯而且安裝了: make && make install 時間會有點長根據我的機器吧,你能夠幹別的事情去! [root@localhost soft]# make && make install > 執行完成也就是安裝完成了, 不過請注意, 這只是安裝了, 並無啓動, 啓動不成功等於沒安裝, 不能用也是徒勞無功不是?
> 進入到 MariaDB 安裝目錄 [root@localhost ~]# cd /usr/local/mysql/ > 使用 `mysql` 用戶執行腳本, 安裝數據庫到數據庫存放目錄 [root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql > 輸出如下信息: Installing MariaDB/MySQL system tables in '/data/mysql' ... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER ! To do so, start the server, then issue the following commands: './bin/mysqladmin' -u root password 'new-password' './bin/mysqladmin' -u root -h localhost.localdomain password 'new-password' Alternatively you can run: './bin/mysql_secure_installation' which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the MariaDB Knowledgebase at http://mariadb.com/kb or the MySQL manual for more instructions. You can start the MariaDB daemon with: cd '.' ; ./bin/mysqld_safe --datadir='/data/maria' You can test the MariaDB daemon with mysql-test-run.pl cd './mysql-test' ; perl mysql-test-run.pl Please report any problems at http://mariadb.org/jira The latest information about MariaDB is available at http://mariadb.org/. You can find additional information about the MySQL part at: http://dev.mysql.com Consider joining MariaDB's strong and vibrant community: https://mariadb.org/get-involved/
> 進行到 MariaDB 安裝目錄 [root@localhost ~]# cd /usr/local/mysql/ > 拷貝support-files目錄下的文件my-large.cnf到/etc目錄並重命名爲my.cnf [root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf
[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql]# /etc/rc.d/init.d/mysqld start
> 打開並新建文件 [root@localhost mysql]# vim /etc/profile.d/mysql.sh > 輸入如下內容 export PATH=$PATH:/usr/local/mysql/bin/ > 保存並退出 :wq > 爲腳本賦於可執行權限 [root@localhost mysql]# chmod 0777 /etc/profile.d/mysql.sh > 進行mysql.sh腳本所在目錄, 並執行腳本, 以當即生效環境變量 [root@localhost mysql]# source /etc/profile.d/mysql.sh
> 運行MariaDB初始化腳本 [root@localhost mysql]# ./bin/mysql_secure_installation > 如下提示: Enter current password for root (enter for none): 輸入當前root密碼(沒有輸入) Set root password? [Y/n] 設置root密碼?(是/否) New password: 輸入新root密碼 Re-enter new password: 確認輸入root密碼 Password updated successfully! 密碼更新成功 By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. 默認狀況下,MariaDB安裝有一個匿名用戶, 容許任何人登陸MariaDB而他們無需建立用戶賬戶。 這個目的是隻用於測試,安裝去更平緩一些。 你應該進入前刪除它們生產環境。 Remove anonymous users? [Y/n] 刪除匿名用戶?(是/否) Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. 一般狀況下,root只應容許從localhost鏈接。 這確保其餘用戶沒法從網絡猜想root密碼。 Disallow root login remotely? [Y/n] 不容許root登陸遠程?(是/否) By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. 默認狀況下,MariaDB提供了一個名爲「測試」的數據庫,任何人均可以訪問。 這也只用於測試,在進入生產環境以前應該被刪除。 Reloading the privilege tables will ensure that all changes made so far will take effect immediately. 從新加載權限表將確保全部到目前爲止所作的更改將當即生效。 Reload privilege tables now? [Y/n] 如今從新加載權限表(是/否) All done! If you've completed all of the above steps, your MariaDB installation should now be secure. 所有完成!若是你已經完成了以上步驟,MariaDB安裝如今應該安全。 Thanks for using MariaDB! 感謝使用MariaDB!
小夥伴們, 通過以上努力, 終因而見到署光的時刻啦!
初始化MariaDB
中沒有設置密碼, 進入MariaDB終端, 直接輸入 mysql
便可[root@localhost ~]# mysql
若是設置了密碼則加入參數vim
mysql --help
進行查看![root@localhost ~]# mysql -u u_setting_username -p
注意: 這部分是對以上編譯安裝後mariadb配置全部操做的一個總結, 看客小夥伴們就不用再次執行了, 爲此有很多小夥伴已入坑?, 博主深表歉意!很差意思讓你入坑了, 實在是罪過哦!?
[root@localhost ~]# cd /usr/local/mysql/ [root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ Installing MariaDB/MySQL system tables in '/data/mysql/' ... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER ! To do so, start the server, then issue the following commands: './bin/mysqladmin' -u root password 'new-password' './bin/mysqladmin' -u root -h localhost.localdomain password 'new-password' Alternatively you can run: './bin/mysql_secure_installation' which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the MariaDB Knowledgebase at http://mariadb.com/kb or the MySQL manual for more instructions. You can start the MariaDB daemon with: cd '.' ; ./bin/mysqld_safe --datadir='/data/mysql/' You can test the MariaDB daemon with mysql-test-run.pl cd './mysql-test' ; perl mysql-test-run.pl Please report any problems at http://mariadb.org/jira The latest information about MariaDB is available at http://mariadb.org/. You can find additional information about the MySQL part at: http://dev.mysql.com Consider joining MariaDB's strong and vibrant community: https://mariadb.org/get-involved/ [root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf [root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld [root@localhost mysql]# /etc/rc.d/init.d/mysqld start Reloading systemd: [ OK ] Starting mysqld (via systemctl): [ OK ] [root@localhost mysql]# touch /etc/profile.d/mysql.sh [root@localhost mysql]# echo 'export PATH=$PATH:/usr/local/mysql/bin/' > /etc/profile.d/mysql.sh [root@localhost mysql]# chmod 0777 /etc/profile.d/mysql.sh [root@localhost mysql]# source /etc/profile.d/mysql.sh [root@localhost mysql]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 10.2.6-MariaDB-log Source distribution Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
但願本文對你的工做和學習有所幫助若是以爲還不錯怎麼感謝我呢? 媽呀! 點贊啊!安全
Good Luck! from warnerwu at 2017.06.24 PM網絡
TODO:dom
Modify correction in 2017.07.13 PM for the first time
Modify correction in 2018.1.4 PM