1. 程式人生 > >LNMP架構二(Mysql資料庫安裝)

LNMP架構二(Mysql資料庫安裝)

二、Mysql資料庫安裝

1、下載mysql二進位制包

[[email protected] src]# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz

2、解壓縮

[[email protected] src]# tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz

[[email protected] src]# mv mysql-5.7.23-linux-glibc2.12-x86_64 /usr/local/mysql

3、修改配置檔案

vi  /etc/my,cnf

[mysqld]
port=3306
character-set-server=utf8
basedir=/usr/local/mysql
datadir=/data
#innodb_buffer_pool_size=8M

[mysqld_safe]

log-error=/data/error.log

pid-file=/data/mysql.pid

tmpdir = /tmp

[client]
default-character-set=utf8
[mysql]
default-character-set=utf8


 

4、建立使用者及使用者組

新增mysql使用者組
#groupadd mysql
給mysql組下新增mysql使用者
#useradd -r -g mysql -s /sbin/nologin mysql
改變檔案所有者和所屬組
#chown -R mysql /usr/local/mysql/
#chgrp -R mysql /usr/local/mysql/

5、解除安裝mariadb

#列出所有被安裝的rpm package
# rpm -qa | grep maria*
mariadb-libs-5.5.56-2.el7.x86_64
# yum -y remove mari*
已載入外掛:fastestmirror
正在解決依賴關係
--> 正在檢查事務
---> 軟體包 mariadb-libs.x86_64.1.5.5.56-2.el7 將被 刪除
......
...
刪除:
  mariadb-libs.x86_64 1:5.5.56-2.el7                              

作為依賴被刪除:
  postfix.x86_64 2:2.10.1-6.el7                                   

完畢!
# rm -rf /var/lib/mysql/*

 

6、將mysql放入系統服務,並修改對應檔案

[[email protected] support-files]# cp mysql.server  /etc/init.d/mysqld

7、初始化安裝

yum install libaio -y

[[email protected] /]# mkdir /data

[[email protected] /]# chown -R mysql:mysql /data

[[email protected] bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data

出現上圖,說明已經安裝成功!

8、啟動mysql

[[email protected] bin]# service mysqld start

9、登陸mysql並輸入5.7初始化時列印的密碼:

10、修改root密碼

mysql>SET PASSWORD FOR 'root'@localhost=PASSWORD('123456');

11、設定root允許遠端連線

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set host='%' where user='root' limit 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 

12、mysql加入環境變數並設定mysql為自啟服務

[[email protected] bin]# vi /etc/profile

新增到最後

export MYSQL_HOME=/usr/local/mysql      

export PATH=$MYSQL_HOME/bin:$PATH

[[email protected] bin]# source /etc/profile   (立即生效)

[[email protected] bin]# chmod +x /etc/rc.d/init.d/mysqld    (新增可執行許可權)

[[email protected] bin]# chkconfig --add mysqld   (新增到開機自啟)

 

參考文章:

https://blog.csdn.net/IsJiangWei/article/details/82875118