centos7 如何安裝MySQL --詳細安裝

本示例爲centos7版本:mysql爲mysql-5.5.56.tar.gz

1.服務器上的卸載原有數據庫

rpm -qa | grep mariadb ###查詢本機有沒有默認的mysql,centos7版本數據庫爲mariadb

rpm -e --nodeps  ###有的話卸載掉

2.下載源碼包

https://www.mysql.com/  ###下載地址

下載好後傳到服務器

3.安裝依賴包

yum -y install make gcc-c++ cmake bison-devel ncurses-devel

4.創建用戶

groupadd mysql

useradd -M -s /sbin/nologin mysql -g mysql

5.解壓,源碼編譯安裝

tar zvxf mysql-5.5.56.tar.gz -C /usr/local/

cd /usr/local/mysql-5.5.56/

編譯:cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLL

ATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all

安裝:make

make install

6.對數據庫目錄進行授權

chmown -R mysql:mysql /usr/local/mysql

7.建立配置文件

拷貝mysql源碼目錄中的support-files文件夾下到/etc/mycnf

cp support-files/my-medium.cnf /etc/my.cnf

8.初始化數據庫

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/loca

l/mysql/data/

9.設置環境變量

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

10.添加系統服務

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

chmod a+x /etc/rc.d/init.d/mysqld

chkconfig --add mysqld

11.啓動數據庫:

service mysqld start

service mysqld status

netstat -anpt | grep mysqld

tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      14245/mysqld

12.訪問數據庫(默認沒有密碼)

mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.5.56-log Source distribution

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

本文檔只寫到怎麼安裝數據庫,下次文檔會寫如何使用數據庫

希望我的文檔能幫助更多的人!——帥小欣


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章