去mariadb官網(wǎng)下載二進制安裝包
進入官網(wǎng)www.mariadb.org選擇 Download
選擇版本
*選擇需要安裝的二進制安裝包
謝謝MariaDB的免費軟件,開源精神是世界的...
安裝環(huán)境
Linux 操作系統(tǒng) CentOS 6.9 版本
創(chuàng)建數(shù)據(jù)庫存放路徑和權(quán)限設(shè)置
[root@host-b app]#pwd
/app
[root@host-b app]#
[root@host-b app]#mkdir /app/data
[root@host-b app]#
[root@host-b app]#rz
[root@host-b app]#getent passwd mysql
[root@host-b app]#
[root@host-b app]#ls
data mariadb-5.5.57-linux-x86_64.tar.gz
[root@host-b app]#
[root@host-b app]#useradd -r -d /app/data -s /sbin/nologin -u 36 mysql
[root@host-b app]#id mysql
uid=36(mysql) gid=36(mysql) groups=36(mysql)
[root@host-b app]#ll
total 218916
drwxr-xr-x. 2 root root 4096 Aug 2 12:33 data
-rw-r--r--. 1 root root 224162771 Aug 2 2017 mariadb-5.5.57-linux-x86_64.tar.gz
[root@host-b app]#
[root@host-b app]#chown mysql:mysql /app/data
[root@host-b app]#ll -d data
drwxr-xr-x. 2 mysql mysql 4096 Aug 2 12:33 data
[root@host-b app]#
解壓縮包
我們安裝的是人家已經(jīng)編譯好了的二進制程序包粘招,所以解壓后路徑不能隨便放拔第,按人家編譯好的環(huán)境來解壓!路徑為
/usr/local
[root@host-b app]#tar xvf mariadb-5.5.57-linux-x86_64.tar.gz -C /usr/local/ <--路徑一定要正確
修改二進制程序的名字和相關(guān)權(quán)限
因為我們安裝的是人家已經(jīng)編譯好的二進制程序包,人家編譯時規(guī)定名字叫mysql标沪,所以我們要修改名字朱沃,或者創(chuàng)建軟連接
修改mysql目錄下的所有文件的所屬組為mysql
到這之后,我們的二進制程序已經(jīng)解壓完了逗物,雖然二進制程序有啦搬卒,但是還不能啟動。如果現(xiàn)在就啟動會報錯的翎卓,比如路徑錯誤等契邀,所以接下來我們還需要修改配置文件
修改配置文件
1. 我們先打開看一下系統(tǒng)自帶的配置文件
2. 利用模板自己創(chuàng)建配置文件
選擇配置文件模板
創(chuàng)建一個配置文件目錄,把模板復(fù)制過去改名為 my.cfg
vim 編輯配給文件失暴,數(shù)據(jù)庫路徑是必須配置
生成對應(yīng)的mysql數(shù)據(jù)庫并放在 /app/data 目錄下
我們用一個腳本生成數(shù)據(jù)庫即可坯门,腳本在解壓縮目錄下的scripts目錄里 :
/mysql_install_db
把 /mysql_install_db 腳本找出來
執(zhí)行腳本 /mysql_install_db 生成數(shù)據(jù)庫
[root@host-b mysql]#pwd
/usr/local/mysql <---執(zhí)行腳本的目錄
[root@host-b mysql]#scripts/mysql_install_db --datadir=/app/data --user=mysql <--指定路徑和用戶
Installing MariaDB/MySQL system tables in '/app/data' ...
170804 4:14:58 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a fu
ture release.170804 4:14:58 [Note] ./bin/mysqld (mysqld 5.5.57-MariaDB) starting as process 4955 ...
OK
Filling help tables...
170804 4:14:59 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a fu
ture release.170804 4:14:59 [Note] ./bin/mysqld (mysqld 5.5.57-MariaDB) starting as process 4963 ...
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 host-b.6.9 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='/app/data'
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@host-b mysql]#
[root@host-b mysql]#ll /app/data <--查看該目錄
total 1084
-rw-rw----. 1 mysql mysql 16384 Aug 4 04:14 aria_log.00000001
-rw-rw----. 1 mysql mysql 52 Aug 4 04:14 aria_log_control
drwx------. 2 mysql root 4096 Aug 4 04:14 mysql <--mysql數(shù)據(jù)庫
-rw-rw----. 1 mysql mysql 30346 Aug 4 04:14 mysql-bin.000001
-rw-rw----. 1 mysql mysql 1038814 Aug 4 04:14 mysql-bin.000002
-rw-rw----. 1 mysql mysql 38 Aug 4 04:14 mysql-bin.index
drwx------. 2 mysql mysql 4096 Aug 4 04:14 performance_schema
drwx------. 2 mysql root 4096 Aug 4 04:14 test
[root@host-b mysql]#
[root@host-b mysql]#
執(zhí)行完 /mysql_install_db 腳本后 /app/data 目錄下生成的數(shù)據(jù)庫文件
把服務(wù)腳本準備好,設(shè)置相關(guān)權(quán)限啟動服務(wù)
(1)把服務(wù)腳本 mysql.server 放到 /etc/inint.d/ 目錄下逗扒,并修改為 mysqld
(2)設(shè)置為開機啟動
(3)創(chuàng)建日志文件 mkdir /var/log/mysql.d 注意路徑
(4)修改日志文件的所屬主為 mysql
(5)service mysqld start 啟動服務(wù)
把二進制程序路徑添加到$PATH變量里
測試并設(shè)置口令
目前我們雖然能夠登陸數(shù)據(jù)庫但是不安全古戴,因為沒有設(shè)置安全口令誰都可以登錄;這樣不安全矩肩。
測試查看端都是否打開:
沒有設(shè)置安全口令之前:
執(zhí)行安全腳本mysql_secure_installation
設(shè)置口令:
執(zhí)行安全腳本
mysql_secure_installation
的代碼塊:
[root@host-b bin]#mysql_secure_installation
/usr/local/mysql/bin/mysql_secure_installation: line 393: find_mysql_client: command not
found
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): <-- 輸入當前root密碼,這里是回車
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y <-- 設(shè)置root密碼么现恼? < y >
New password: <-- 這里輸入密碼
Re-enter new password: <-- 再輸入一次密碼
Password updated successfully!
Reloading privilege tables..
... Success!
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.
Remove anonymous users? [Y/n] y <-- 是否刪除匿名用戶? < y >
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n <-- 是否禁止root遠程登錄? < n >
... skipping.
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.
Remove test database and access to it? [Y/n] n <-- 是否刪除測試數(shù)據(jù)庫述暂? < y/n都可以 >
... skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y <-- 現(xiàn)在從新加載權(quán)限表么痹升? < y >
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@host-b bin]#
設(shè)置安全口令之后:
結(jié)語
到這里就完成整個MariaDB數(shù)據(jù)庫的二進制安裝!自己學(xué)習用的畦韭,如果能夠幫到讀者是我的榮幸疼蛾;
最后還要感謝MariaDB數(shù)據(jù)庫的開發(fā)者們免費提供的軟件,開源精神是世界的艺配!