1. 程式人生 > >centos7.3二進制安裝mariadb

centos7.3二進制安裝mariadb

linux


centos7.3二進制安裝mariadb.10.2.8


1.確認沒有maraiadb*

rpm -qa mariadb*查看無包即可,若有,用yum remove卸載


2.useradd -d /app/mysqldb -r -m -s /sbin/nologin mysql

getent passwd mysql

建議放在邏輯卷上,數據庫會不斷變大,不能擴展的分區後期處理起來就麻煩多了。


3. tar xf mariadb-VERSION-linux-x86_64.tar.gz -C /usr/local

cd /usr/local

ln -sv mariadb-10.2.8-linux-x86_64 mysql v顯示過程


4.準備配置文件

cd /usr/local/mysql

ls support-files/

mkdir /etc/mysql

cp /usr/local/mysqlsupport-files/my-huge.cnf /etc/mysql/my.cnf

vim /etc/mysql/my.cnf

[mysqld]

datadir = /app/mysqldb 必須加

innodb_file_per_table = on 每表為一獨立文件

skip_name_resolve = on 性能優化,禁止主機名解析


5../scripts/mysql_install_db --user=mysql --datadir=/app/mysqldb 運行腳本,創建系統數據庫

ls /app/mysqldb 有東西了

(可能有報錯,根據報錯提醒,逐一排錯)

因為是二進制編譯,有些配置文件的位置是設定好的,這點需註意。

[[email protected] mysql]# ./scripts/mysql_install_db --datadir=/app/mysqldb --user=mysql
Installing MariaDB/MySQL system tables in ‘/app/mysqldb‘ ...
2017-10-11 20:08:53 140592457275200 [Warning] ‘THREAD_CONCURRENCY‘ is deprecated and will be removed in a future release.
2017-10-11 20:08:55 140592457275200 [ERROR] ./bin/mysqld: unknown variable ‘datedir=/app/mysqldb‘
2017-10-11 20:08:55 140592457275200 [ERROR] Aborting


6.準備服務腳本,並啟動服務

cp support-files/mysql.server /etc/init.d/mysqld

chkconfig --list mysqld

chkconfig --add mysqld

service mysqld start

下面是服務不能啟動的情況

[[email protected] mysql]# service mysqld start
Starting mysqld (via systemctl):  Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
                                                           [FAILED]
[[email protected] mysql]# systemctl status mysqld.service -l
● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2017-10-11 20:20:27 CST; 3min 32s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 10519 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)

Oct 11 20:20:26 centos7.magedu.com systemd[1]: Starting LSB: start and stop MySQL...
Oct 11 20:20:26 centos7.magedu.com mysqld[10519]: Starting MySQL.171011 20:20:26 mysqld_safe Logging to ‘/var/log/mariadb/mariadb.log‘.
Oct 11 20:20:26 centos7.magedu.com mysqld[10519]: 171011 20:20:26 mysqld_safe Starting mysqld daemon with databases from /app/mysqldb
Oct 11 20:20:26 centos7.magedu.com mysqld[10519]: [133B blob data]
Oct 11 20:20:27 centos7.magedu.com mysqld[10519]: ERROR!
Oct 11 20:20:27 centos7.magedu.com systemd[1]: mysqld.service: control process exited, code=exited status=1
Oct 11 20:20:27 centos7.magedu.com systemd[1]: Failed to start LSB: start and stop MySQL.
Oct 11 20:20:27 centos7.magedu.com systemd[1]: Unit mysqld.service entered failed state.
Oct 11 20:20:27 centos7.magedu.com systemd[1]: mysqld.service failed.

可以看到缺少了日誌文件,日誌文件對於mysql數據庫還是很重要的。有時出現任務進行一半意外中斷的情況,日誌可以快速排錯。接下來我們創建日誌文件。註意權限。權限不對會導致服務無法啟動。

touch /var/log/mariadb/mariadb.log

chown mysql /var/log/mariadb/mariadb.log

chown mysql /var/log/mariadb

service mysqld start


7.安全初始化環境配置

主要包括PATH環境變量及安全環境。

[[email protected] mysql]# vim /etc/profile.d/mysql.sh

PATH=/usr/local/mysql/bin/:$PATH

可以同時開一個終端測試.

A:

[[email protected] bin]# cd /usr/local/mysql/bin
[[email protected] bin]# ./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):

B:查看當前登錄用戶

[[email protected] ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.2.8-MariaDB-log MariaDB Server
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)]> select user();
+----------------+
| user()         |
+----------------+
| [email protected] |
+----------------+
1 row in set (0.00 sec)

A:

[[email protected] bin]# ./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): 
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
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]

B:

[[email protected] ~]# mysql
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)

設置完成後再以root身份登錄就要執行mysql -uroot -p命令了。



本文出自 “RightNow” 博客,請務必保留此出處http://amelie.blog.51cto.com/12850951/1971534

centos7.3二進制安裝mariadb