1. 程式人生 > >二進制安裝MySQL

二進制安裝MySQL

二進制 Mysql 編譯安裝

二進制格式的安裝方式如下:


1.查詢本地是否安裝mysql數據庫相關的軟件包(卸載之)

rpm -qa "mysql*"   (centos6)

rpm -qa "mariaDB*" (cetos7)

2.mariadb.org下載源碼二進制包帶有linux字樣的已經編譯過的包:

mariadb-10.2.12-linux-x86_64.tar.gz(大小440M左右因為已經編譯過)

3. 準備用戶

getent passwd mysql  查詢passwd是否有mysql用戶

useradd -r mysql -s /sbin/nologin  創建mysql系統用戶

[root@centos7 ~ 13]#id mysql

uid=990(mysql) gid=305(mysql) groups=305(mysql)

生產環境建議置後一個版本至少.

4.解壓mariadb-10.2.12-linux-x86_64.tar.gz

4-1. tar xvf  mariadb-10.2.12-linux-x86_64.tar.gz -C /usr/local/

註意:解壓目錄指定,因為這是已經編譯過的源碼包所以路徑很重要需要解壓到/usr/local/下

4-2.需要改名因為編譯之前的目錄叫mysql;

建議創建軟連接:

ln -s mariadb-10.2.12-linux-x86_64/ mysql

5.修改文件權限默認沒有屬主屬組:(可以不做修改)

chown -R mysql.mysql mysql/

6.導出環境變量:

echo ‘PATH=/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh

cat /etc/profile.d/mysql.sh

. /etc/profile.d/mysql.sh (重讀配置文件)

7.準備數據目錄;建議使用邏輯卷

7-1.創建邏輯卷:

fdiak /dev/sda

7-2.同步磁盤:

partprobe (6 使用pertx)

7-3.創建PV物理卷:

pvcreate /dev/sda6

7-4. 創建卷組:

vgcreate vg0-mysqldata /dev/sda6 -s 16M

7-5.查看卷組:

vgdisplay

7-6.創建LVM

lvcreate -n lv_mysqldata -l 100%FREE vg0mysqldata

7-7.創建邏輯卷的文件系統:

mkfs.xfs /dev/vg0mysqldata/lv_mysqldata

8.創建掛載點並且掛載添加/etc/fstab條目(請註意當前所在的工作目錄.我當前的路徑是在/usr/local/mysql/bin)

mkdir -pv /data/mysqldb

echo ‘ UUID=98833275-08ee-446f-b888-3e03557deedf /data/mysqldb xfs defaults 0  0‘ >> /etc/fstab (建議別這麽添加清空了這個文件就尷尬了)

mount -a 重讀/etc/fsatb

9.這連個就是mysql的數據庫目錄了安全起見建議修改權限為770

chmod 770 /data/mysqldb/

10.初始化數據庫:

cd scripts/

scripts/mysql_install_db --datadir=/data/mysqldb --user=mysql

註意:這個腳本一定要在它的上一級目錄執行否則會報錯

11.由於默認的配置文件過於簡陋而且數據庫路徑也不對,可參考/usr/local/mysql/support-files/目錄下以.cnf結尾的模版配置文件.

11-1.cp my-huge.cnf /etc/my.cnf (覆蓋目標文件)

修改如下:

12.運行/usr/local/mysql/mysql-server 服務腳本

cp mysql.server /etc/init.d/mysqld 復制並改名mysqld

chkconfig --add mysqld   添加到系統腳本開機啟動

13.啟動服務:

service mysqld start

源碼安裝結束

14.查看是否有錯誤信息

15.查看端口3306

ss -tnl

16.mysql安裝完成默認沒有密碼需要運行一個安全腳本:

. /mysql_secure_installation (交互式設置密碼及刪除匿名用戶)

[root@centos7 /usr/local/mysql/bin 178]# ./mysql_secure_installation

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  是否設置root口令

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  刪除匿名用戶

... 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遠程等

... 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] y  是否刪除test測試數據庫(隨機附帶的測試數據庫)

- Dropping test database...

... Success!

- Removing privileges on test database...

... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/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!

數據化的安全腳本執行完畢後就可以啟動服務並測試命令行連接MySQL.

二進制安裝MySQL