在Centos7上搭建Mysql資料庫

來源:互聯網
上載者:User

標籤:general   base   mon   insecure   file   關閉   ble   ase   server   

mysql服務基礎:

mysql是一個真正的多線程、多使用者的SQL資料庫服務,憑藉其高效能、高可靠和便於使用的特性,成為伺服器領域中最受歡迎的開來源資料庫系統。

MySQL的編譯安裝:

1.安裝支援軟體

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

2.建立運行使用者mysql,並解壓mysql源碼包到/opt/目錄下,將boost源碼包解壓到/usr/local/ 目錄下,將解壓後的boost包重新命名方便管理。

useradd -s /sbin/nologin mysqltar zxvf mysql-5.7.17.tar.gz -C /opt/tar zxvf boost_1_59_0.tar.gz -C /usr/local/cd /usr/local/mv boost_1_59_0 boost

3.在配置過程中,可以將預設使用的字元集設定為utf8,並添加其他字元集的支援。

cd mysql-5.7.17/-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \       //安裝目錄//-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \  -DSYSCONFDIR=/etc \                            //指定初始化參數檔案目錄//-DSYSTEMD_PID_DIR=/usr/local/mysql -DDEFAULT_CHARSET=utf8  \                    //指定預設使用的字元集編碼//-DDEFAULT_COLLATION=utf8_general_ci \       //適用於UTF-8字元集的通用規則//-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_BOOST=/usr/local/boost \            //指定Boost庫的位置,5.7版本必須添加這個參數-DWITH_SYSTEMD=1

------注意:如果在CMAKE的過程中有報錯,當報錯解決後,需要把源碼目錄中的CMakeCache.txt檔案刪除,然後再重新CMAKE,否則錯誤依舊------------

4.編譯並安裝

make          make install

------注意:如果在make載入過程中,中途卡死,把虛擬機器的記憶體設定為2G,再進行make編譯//,如果再make編譯過程中出現error報錯,可用以下方法解決:下載mysql-boost-5.7包並進行解壓,在進行配置,把boost函數庫位置由-DWITH_BOOST=/usr/local/boost \改為-DWITH_BOOST=boost \

5.對資料庫的目錄進行使用權限設定

chown -R mysql.mysql /usr/local/mysql/

6.在MySQL源碼目錄中的support-files檔案夾下,建立MySQL系統的/etc/my.cnf設定檔。

vi /etc/my.cnf[client]port = 3306default-character-set=utf8socket = /usr/local/mysql/mysql.sock[mysql]port = 3306default-character-set=utf8socket = /usr/local/mysql/mysql.sock[mysqld]user = mysqlbasedir = /usr/local/mysqldatadir = /usr/local/mysql/dataport = 3306character_set_server=utf8pid-file = /usr/local/mysql/mysqld.pidsocket = /usr/local/mysql/mysql.sockserver-id = 1sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

7.修改/etc/my.cnf即主設定檔的屬主和屬組

chown mysql:mysql /etc/my.cnf

8.設定環境變數,為了方便在任何目錄下使用mysql命令,需要在/etc/profile設定環境變數。

echo ‘PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH‘ >> /etc/profileecho ‘export PATH‘ >> /etc/profilesource /etc/profile       //開啟//

9.初始化資料庫,為了能夠正常使用MySQL資料庫系統,應以運行使用者mysql的身份執行初始化,指定資料存放目錄等。

cd /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

10.添加mysqld系統服務,以便通過systemctl進行管理,可以直接使用源碼包中提供的服務指令碼。找到usr/lib/systemd/system/檔案夾下的mysql.server指令檔,將其複製到/usr/lib/systemd/目錄下,並改名為system,然後再進行重新載入。

cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/systemctl daemon-reload    //重新載入系統服務管理模組

11.啟動mysqld服務並查看TCP3306連接埠是否開啟

systemctl start mysqldnetstat -anpt | grep 3306[[email protected] mysql]# netstat -anpt | grep 3306tcp6       0      0 :::3306                 :::*                    LISTEN      23765/mysqld        

12.關閉防火牆

systemctl stop firewalld.service setenforce 0

13.設定資料庫的root登入密碼

mysqladmin -u root -p password "abc123"

14.登入資料庫

[[email protected] mysql]# mysql -u root -pEnter password:       Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.7.17 Source distributionCopyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘abc123‘ with grant option;Query OK, 0 rows affected, 1 warning (0.00 sec)

15.查看資料庫結構

mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || sys                |+--------------------+4 rows in set (0.00 sec)

在Centos7上搭建Mysql資料庫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.