您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關Linux下如何使用Systemd編譯Mysql5.7.11,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
Systemd 是 Linux 系統工具,用來啟動守護進程,已成為大多數發行版的標準配置。
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
源碼包有兩種版本 : mysql-5.7.11.tar.gz 不帶 boost庫 ,需要自行下載。
mysql-boost-5.7.11.tar.gz 自帶 boost庫,在解壓后的根目錄,推薦下載。 wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-boost-5.7.11.tar.gz
curl -O http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-boost-5.7.11.tar.gz
tar -zxf mysql-boost-5.7.11.tar.gz
cd mysql-5.7.11
生成makefile“
cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DSYSCONFDIR=/etc \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DMYSQL_TCP_PORT=3306 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ [字符集] -DDEFAULT_COLLATION=utf8_general_ci \ [排序規則 必須有,不然初始化數據庫困難] -DDOWNLOAD_BOOST=1 \ [從MySQL 5.7.5開始Boost庫是必需的] -DWITH_BOOST=/root/mysql-5.7.11/boost \ -DWITH_SYSTEMD=1 [支持Systemd] 加上-DWITH_SYSTEMD=1可以使用systemd控制mysql服務,默認是不開啟systemd的。
然后 make -j 2 && make install
mysql將會安裝到/usr/local/mysql路徑 慢慢等……
添加mysql用戶和組
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
修改/usr/local/mysql權限
chown -R mysql:mysql /usr/local/mysql
創建 mysql PID 默認目錄
在 mysqld.service ,把默認的pid文件指定到了 /var/run/mysqld/ 目錄,而并沒有事先建立該目錄,因此要手動建立該目錄并把權限賦給 mysql 用戶。 mkdir -p /var/run/mysqldchown mysql:mysql /var/run/mysqld
mysql 三個運行文件默認位置
log : /var/log/mysqld.logpid : /var/run/mysqld/mysqld.pidsock : /tmp/mysql.sock
拷貝 my.cnf 和 mysqld.service
cp support-files/my-default.cnf /etc/my.cnf
mysql 5.7 默認將 mysqld.service (/usr/local/mysql/)文件安裝到了 mysql 安裝目錄下的 usr/lib/systemd/system/,將 mysqld.service 復制到/usr/lib/systemd/system/目錄下 [root@localhost]/usr/local/mysql#cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system
添加環境變量
— 編輯/etc/profile文件在最后添加如下兩行 — “
vim /etc/profile
PATH=/usr/local/mysql/bin:$PATH export PATH
source /etc/profile
初始化 無密碼 mysql 數據庫
bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/databin/mysql_ssl_rsa_setup
出現下列內容,初始化成功 2016-02-22T03:56:27.254356Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the –initialize-insecure option.
-–initialize 會生成一個隨機密碼(保存在~/.mysql_secret),而 -–initialize-insecure 不會生成密碼,在MySQL安全配置向導mysql_secure_installation設置密碼時,可自由選擇 mysql 密碼等級。
-–datadir目標目錄下不能有數據文件。
之前版本初始化程序 mysql_install_db 是在 /usr/local/mysql/script 下,并會在將來被移除,轉而使用mysqld替代 已被廢棄 mysql5.7 放在了 /usr/local/mysql/bin 目錄下。
啟動 mysql
systemctl start mysqld.service
systemctl status mysqld.service
運行 MySQL安全配置向導mysql_secure_installation 設置密碼,mysql 服務啟動后才可執行
a)為root用戶設置密碼 b)刪除匿名賬號 c)取消root用戶遠程登錄 d)刪除test庫和對test庫的訪問權限 e)刷新授權表使修改生效 [root@localhost mysql]# mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password. [使用空密碼連接到MySQL]
VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin?[VALIDATE密碼插件可以被用來測試密碼 并提高安全性。你是否想設置VALIDATE密碼插件?]
Press y|Y for Yes, any other key for No: y
There are three levels of password validation policy: [有三種級別的密碼驗證策略:]
LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file [最小長度> = 8 中等長度> = 8,數字,大小寫混合和特殊字符 最長長度> = 8,數字,混合大小寫,特殊字符和字典文件]
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 [請輸入0 =低,1 =中2 =強:0] Please set the password for root here. [請在這里設置root用戶的密碼。]
New password: [新密碼:]
Re-enter new password: [重新輸入新密碼:]
Estimated strength of the password: 25 [密碼的估計強度:25] Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y [您是否希望繼續與提供的密碼(按y | Y表示是,因為沒有任何其他鍵):Y?] … Failed! Error: Your password does not satisfy the current policy requirements [ … 失敗!錯誤:您的密碼不符合當前的要求]
New password:
Re-enter new password:
Estimated strength of the password: 50 [密碼的估計強度:50] Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL 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. [默認情況下,MySQL安裝有一個匿名用戶, 允許任何人登錄到MySQL.]
Remove anonymous users? (Press y|Y for Yes, any other key for No) : 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. [通常情況下,Root 只允許其進行’localhost'(本地) 連接 。]
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n [禁止遠程root登錄?]
… skipping. […跳過。] By default, MySQL 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. [默認情況下,MySQL帶有一個名為“測試”數據庫,任何人都可以訪問。這也是僅用于測試,并且應該移動到生產之前被刪除環境。]
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n [刪除測試數據庫和訪問權限?]
… skipping. [ …跳過。] Reloading the privilege tables will ensure that all changes made so far will take effect immediately. [刷新授權表以確保所有的變化取得將立即生效。]
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : [現在刷新授權表?]
… skipping. All done! [全部完成!]
開放 Root 遠程連接權限
mysql -u root -p mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; [password 為遠程連接密碼] mysql>FLUSH PRIVILEGES; [刷新權限]
關于“Linux下如何使用Systemd編譯Mysql5.7.11”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。