設置Mariadb的yum源 mysql
vim /etc/yum.repos.d/mariadb.repo [mariadb] name=mariadb baseurl=https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/10.2/centos7-amd64/ gpgcheck=0
使用清華yum源安裝Mariadb,能夠選擇不一樣的版本,此處安裝10.2.23 yum install mariadb-server
linux
1 準備mysql用戶和組 sql
groupadd -r -g 336 mysql #建立mysql組 useradd -r -g mysql -u 336 -s /sbin/nologin -d /data/mysql mysql #建立mysql用戶,並加入mysql用戶組,設置UID爲336,設置默認shell爲nologoin,家目錄爲/data/mysql 但不自動建立
2 準備二進制程序文件和相關文件屬性 shell
tar xvf mariadb-10.2.23-linux-x86_64.tar.gz -C /usr/local #只能放在此目錄中 cd /usr/local/ ln -s mariadb-10.2.23-linux-x86_64/ mysql #創建軟件連接,方便使用 chown -R root.root /usr/local/mysql/ #設置屬主和屬組爲root用戶和root組
3 PATH變量 數據庫
vim /etc/profile.d/mysql.sh PATH=/usr/local/mysql/bin:$PATH . /etc/profile.d/mysql.sh
4 準備數據庫數據目錄和數據(使用邏輯卷) vim
建立邏輯卷 pvcreate /dev/sda6 建立卷組 vgcreate vg0 /dev/sda6 建立邏輯卷 lvcreate -n mysql -L 20G /dev/vg0 建立文件系統並掛載到/data/mysql mkfs.xfs /dev/vg0/mysql mkdir /data/mysql mount /dev/vg0/mysql /data/mysql chown mysql.mysql /data/mysql/ cd /usr/local/mysql ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql #安裝mysql到/data/mysql目錄下,用戶爲mysql
5 準備Mysql的服務器端配置文件 centos
mkdir /etc/mysql cp /usr/local/mysql/support-files/my-huge.cnf /etc/mysql/my.cnf vim /etc/mysql/my.cnf [mysqld] datadir=/data/mysql #設置目錄爲/data/mysql
6 準備服務啓動腳本 安全
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chkconfig --add mysqld service mysqld start
7 安全加固 服務器
[root@Centos7 ~]#/usr/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 #設置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] y #禁止root遠程登陸 ... Success! 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!
8 測試鏈接
mysql -uroot -pPASSWORD ide