首頁  >  文章  >  資料庫  >  怎麼透過Systemd編譯Mysql5.7.11

怎麼透過Systemd編譯Mysql5.7.11

WBOY
WBOY轉載
2023-05-29 18:46:261149瀏覽

怎麼透過Systemd編譯Mysql5.7.11


MySQL 5.7主要功能:

原生支援Systemd 更好的效能:對於多核心CPU、固態硬碟、鎖定有著更好的優化更好的InnoDB儲存引擎更為健壯的複製功能:複製帶來了資料完全不遺失的方案,傳統金融客戶也可以選擇使用MySQL資料庫。此外,GTID在線平滑升級也變得可能更好的優化器:優化器程式碼重構的意義將在這個版本及以後的版本中帶來巨大的改進,Oracle官方正在解決MySQL之前最大的難題原生JSON類型的支援更好的地理資訊服務支援:InnoDB原生支援地理位置類型,支援GeoJSON,GeoHash特性新增sys庫:以後這會是DBA存取最頻繁的庫MySQL 5.7已經作為資料庫可選項新增至OneinStack — lnmp安裝工具中

安裝依賴包

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

#下載mysql源碼包

源碼包有兩種版本: 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

# 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 \ -LEDMYSQL_TCP_PORT=3306 -DENAB3306_DEN-LEDD _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/5.7.11/ boost \ -DWITH_SYSTEMD=1 [支援Systemd] 加上 -DWITH_SYSTEMD=1可以使用systemd控制mysql服務,預設是不開啟systemd的。

然後make -j 2 && make install# mysql將會安裝到/usr/local/mysql路徑慢慢等……

配置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

mysql -u root -p
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; [password 为远程连接密码]
mysql>FLUSH PRIVILEGES; [刷新权限]

mysql 5.7 預設將mysqld.service

##rrreeemysql 5.7 預設將mysqld.service##rrreee

mysql 5.7 預設將mysqld.service (/usr/local/mysql/)檔案安裝到了mysql 安裝目錄下的usr/lib/systemdusr/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 itching alease consider.

#-–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登录?]

...omitting. [省略]。] 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 [删除测试数据库和访问权限?]

... omitting. [ ...省略。] 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; [刷新权限]

以上是怎麼透過Systemd編譯Mysql5.7.11的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:yisu.com。如有侵權,請聯絡admin@php.cn刪除