對於mysql的資料庫的安裝,我們有很多選擇可以完成。而最為常用的為二進位安裝以及原始碼安裝。二進位安裝方式中,包括rpm版本以及glibc版本。 rpm版本就是在特定linux版本下編譯的,如果你的linux版本匹配,就可以安裝,例如針對RedHat6或RedHat7編譯好的rpm包,下載對應的安裝即可。還有另外一種二進位安裝包是為基於特定的glibc版本編譯的,本文主要描述基於glibc方式安裝mysql。
一、準備安裝環境
###准备安装介质下载地址:http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz ###或者使用wget方式直接下载对应的版本 # wget http://www.php.cn/# mkdir -pv /u01/app# mkdir -pv /u01/soft# mkdir -pv /u02/mysqldata# cd /u01/soft# wget http://www.php.cn/ # tar -xf mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz# ln -sv /u01/soft/mysql-5.7.12-linux-glibc2.5-x86_64 /u01/app/mysql`/u01/app/mysql' -> ` /u01/soft/mysql-5.7.12-linux-glibc2.5-x86_64'###下面添加mysql用户# useradd -r mysql -s /sbin/nologin# chown -R mysql:mysql /u01/app/mysql # chown -R mysql:mysql /u02/mysqldata
二、初始化mysql
###使用以下的方式来初始化# cd /u01/app/mysql/bin# ./mysqld --initialize --basedir=/u01/app/mysql --datadir=/u02/mysqldata --user=mysql --explicit_defaults_for_timestamp2016-06-28T02:18:23.437852Z 0 [Warning] InnoDB: New log files created, LSN=457902016-06-28T02:18:23.718104Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2016-06-28T02:18:23.866501Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9731b834-3cd6-11e6-8654-fcaa14e34b30.2016-06-28T02:18:23.896540Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2016-06-28T02:18:23.898416Z 1 [Note] A temporary password is generated for root@localhost: )%%D0pr,mU.Y# ls /u02/mysqldata/auto.cnf client-cert.pem ibdata1 performance_schema sys ca-key.pem client-key.pem ib_logfile0 server-cert.pem ca.pem client-req.pem ib_logfile1 server-key.pem ca-req.pem ib_buffer_pool mysql server-req.pem###从上面的结果可以看出 mysql 5.7多出了证书相关文件,安全较5.6有较大提升 ###mysql_install_db方式初始化数据已经被废弃# ./mysql_install_db --basedir=/u01/app/mysql --datadir=/u02/mysqldata --user=mysql2016-06-28 10:04:56 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize2016-06-28 10:05:15 [WARNING] The bootstrap log isn't empty:2016-06-28 10:05:15 [WARNING] 2016-06-28T02:04:56.688237Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead2016-06-28T02:04:56.688654Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)2016-06-28T02:04:56.688657Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)###如上书提示,mysql_install_db方式初始化数据已经被废弃,建议使用mysqld --initialize,同时也给出了参数限制的警告 # cp /u01/app/mysql/support-files/my-default.cnf /etc/my.cnf# cp /u01/app/mysql/support-files/mysql.server /etc/init.d/mysqld# vim /etc/my.cnf [mysqld] sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES basedir=/u01/app/mysql datadir=/u02/mysqldata user=mysql port=3306# vim /etc/profile.d/mysql.shexport MYSQL_HOME=/u01/app/mysql export PATH=$PATH:$MYSQL_HOME/bin# source /etc/profile.d/mysql.sh# service mysqld startStarting MySQL. [ OK ]
三、設定安全選項
###使用初始化时得到的密码配置安全选项 # /u01/app/mysql/bin/mysql_secure_installation -p)%%D0pr,mU.Y mysql_secure_installation: [Warning] Using a password on the command line interface can be insecure. Securing the MySQL server deployment. The existing password for the user account root has expired. Please set a new password. New password: Re-enter new password: VALIDATE PASSWORD PLUGIN can be used to test passwordsand improve security. It checks the strength of passwordand allows the users to set only those passwords which aresecure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: y ###是否校验密码插件 There are three levels of password validation policy: LOW Length >= 8MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 ###设定密码策略等级Using existing password for root. Estimated strength of the password: 100 Change the password for root ? ((Press y|Y for Yes, any other key for No) : ... skipping.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 fortesting, and to make the installation go a bit smoother. You should remove them before moving into a production environment. 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 atthe root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y ###是否关闭root远程登陆功能 Success.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. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y ###是否移除测试数据库 - Dropping test database... Success. - Removing privileges on test database... Success. 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) : y ###是否立即生效权限表 Success.All done! ###以下为安全增强相关的部分参数 mysql> show variables like 'valid%';+--------------------------------------+--------+| Variable_name | Value | +--------------------------------------+--------+| validate_password_dictionary_file | | | validate_password_length | 8 | | validate_password_mixed_case_count | 1 | | validate_password_number_count | 1 | | validate_password_policy | STRONG | | validate_password_special_char_count | 1 | +--------------------------------------+--------+
四、同一主機配置其他實例參考5 下安裝MySQL 5.6(RPM方式)
Linux 下卸載MySQL 5Linux下基於源碼方式安裝MySQL 5.6
Linux 下MySQL源碼安裝完整版MySQL 代碼scr.rpmrpm安裝源的一點注意事項。的安裝,我們有很多選擇來完成。而最為常用的為二進位安裝以及原始碼安裝。二進位安裝方式中,包括rpm版本以及glibc版本。 rpm版本就是在特定linux版本下編譯的,如果你的linux版本匹配,就可以安裝,例如針對RedHat6或RedHat7編譯好的rpm包,下載對應的安裝即可。還有另外一種二進位安裝包是為基於特定的glibc版本編譯的,本文主要描述基於glibc方式安裝mysql。
一、準備安裝環境
###按上面描述的步骤创建其对应的目录及授权后,再执行初始化###使用新的配置文件,如下文本示例使用的为3317# mkdir -pv /u02/mysqldata3317# chown -R mysql:mysql /u02/mysqldata 3317# grep -v ^# /etc/my3317.cnf[mysqld] basedir=/u01/app/mysql datadir=/u02/mysqldata3317 user=mysql port=3317socket=/tmp/mysql3317.sock# cd /u01/app/mysql/bin# ./mysqld --defaults-file=/etc/my3317.cnf --initialize --user=mysql --explicit_defaults_for_timestamp# 2016-06-30T08:32:52.497519Z 0 [Warning] InnoDB: New log files created, LSN=457902016-06-30T08:32:52.852457Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2016-06-30T08:32:53.042621Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 3cb1686d-3e9d-11e6-a71f-fcaa14e34b30.2016-06-30T08:32:53.081210Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2016-06-30T08:32:53.082538Z 1 [Note] A temporary password is generated for root@localhost: :8 #l!MCYoCNY### Author : Leshami### Blog : http://www.php.cn/# mysqld_safe --defaults-file=/etc/my3317.cnf &[1] 58252016-06-30T08:11:49.468176Z mysqld_safe Logging to '/u02/mysqldata3317/ydq4.err'.2016-06-30T08:11:49.480379Z mysqld_safe The file /usr/local/mysql/bin/mysqld does not exist or is not executable. Please cd to the mysql installation directory and restart this script from there as follows: ./bin/mysqld_safe& See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information###如果执行mysqld_safe出现上述错误,可以创建软链。 这个地方有问题,对于安装在非缺省目录时出现了这个问题。# mkdir -pv /usr/local/mysql/bin/# ln -sv /u01/app/mysql/bin/mysqld /usr/local/mysql/bin/mysqld "/usr/local/mysql/bin/mysqld" -> "/u01/app/mysql/bin/mysqld"# ./mysqld_safe --defaults-file=/etc/my3317.cnf &[1] 82872016-06-30T08:38:38.455961Z mysqld_safe Logging to '/u02/mysqldata3317/ydq4.err'.2016-06-30T08:38:38.471542Z mysqld_safe Starting mysqld daemon with databases from /u02/mysqldata3317###配置安全选项# /u01/app/mysql/bin/mysql_secure_installation -P3317 -S /tmp/mysql3317.sock -p
二、初始化mysql
###准备安装介质下载地址:http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz ###或者使用wget方式直接下载对应的版本 # wget http://www.php.cn/# mkdir -pv /u01/app# mkdir -pv /u01/soft# mkdir -pv /u02/mysqldata# cd /u01/soft# wget http://www.php.cn/ # tar -xf mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz# ln -sv /u01/soft/mysql-5.7.12-linux-glibc2.5-x86_64 /u01/app/mysql`/u01/app/mysql' -> ` /u01/soft/mysql-5.7.12-linux-glibc2.5-x86_64'###下面添加mysql用户# useradd -r mysql -s /sbin/nologin# chown -R mysql:mysql /u01/app/mysql # chown -R mysql:mysql /u02/mysqldata
三、配置安全選項
###使用以下的方式来初始化# cd /u01/app/mysql/bin# ./mysqld --initialize --basedir=/u01/app/mysql --datadir=/u02/mysqldata --user=mysql --explicit_defaults_for_timestamp2016-06-28T02:18:23.437852Z 0 [Warning] InnoDB: New log files created,LSN=457902016-06-28T02:18:23.718104Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2016-06-28T02:18:23.866501Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9731b834-3cd6-11e6-8654-fcaa14e34b30.2016-06-28T02:18:23.896540Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2016-06-28T02:18:23.898416Z 1 [Note] A temporary password is generated for root@localhost: )%%D0pr,mU.Y# ls /u02/mysqldata/auto.cnf client-cert.pem ibdata1 performance_schema sys ca-key.pem client-key.pem ib_logfile0 server-cert.pem ca.pem client-req.pem ib_logfile1 server-key.pem ca-req.pem ib_buffer_pool mysql server-req.pem###从上面的结果可以看出 mysql 5.7多出了证书相关文件,安全较5.6有较大提升 ###mysql_install_db方式初始化数据已经被废弃# ./mysql_install_db --basedir=/u01/app/mysql --datadir=/u02/mysqldata --user=mysql2016-06-28 10:04:56 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize2016-06-28 10:05:15 [WARNING] The bootstrap log isn't empty:2016-06-28 10:05:15 [WARNING] 2016-06-28T02:04:56.688237Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead2016-06-28T02:04:56.688654Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)2016-06-28T02:04:56.688657Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000) ###如上书提示,mysql_install_db方式初始化数据已经被废弃,建议使用mysqld --initialize,同时也给出了参数限制的警告 # cp /u01/app/mysql/support-files/my-default.cnf /etc/my.cnf# cp /u01/app/mysql/support-files/mysql.server /etc/init.d/mysqld# vim /etc/my.cnf [mysqld] sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES basedir=/u01/app/mysql datadir=/u02/mysqldata user=mysql port=3306# vim /etc/profile.d/mysql.shexport MYSQL_HOME=/u01/app/mysql export PATH=$PATH:$MYSQL_HOME/bin# source /etc/profile.d/mysql.sh# service mysqld startStarting MySQL. [ OK ]
四、同一主機配置其他實例參考MySQL 5.6(RPM方式)Linux 下MySQL源碼安裝完整版Linux 下卸載MySQL 5
Linux下基於源碼方式安裝MySQL 5.6
MySQL 源碼scr.rpm安裝的一點注意事項
內容請關注PHP中文網(www.php.cn)!
如何有效監控MySQL性能?使用mysqladmin、SHOWGLOBALSTATUS、PerconaMonitoringandManagement(PMM)和MySQLEnterpriseMonitor等工具。 1.使用mysqladmin查看連接數。 2.用SHOWGLOBALSTATUS查看查詢數。 3.PMM提供詳細性能數據和圖形化界面。 4.MySQLEnterpriseMonitor提供豐富的監控功能和報警機制。

MySQL和SQLServer的区别在于:1)MySQL是开源的,适用于Web和嵌入式系统,2)SQLServer是微软的商业产品,适用于企业级应用。两者在存储引擎、性能优化和应用场景上有显著差异,选择时需考虑项目规模和未来扩展性。

在需要高可用性、高級安全性和良好集成性的企業級應用場景下,應選擇SQLServer而不是MySQL。 1)SQLServer提供企業級功能,如高可用性和高級安全性。 2)它與微軟生態系統如VisualStudio和PowerBI緊密集成。 3)SQLServer在性能優化方面表現出色,支持內存優化表和列存儲索引。

mySqlManagesCharacterSetsetSandCollationsyutusututf-8asthEdeFault,允許ConfigurationAtdataBase,table和columnlevels,AndrequiringCarefullageLignmentToavoidMismatches.1)setDefeaultCharactersetTercharactersetEtCollacterSeteTandColletationForAdataBase.2)conformentcollecharactersettersetertersetcollatertersetcollationcollation

MySQL觸發器是與表相關聯的自動執行的存儲過程,用於在特定數據操作時執行一系列操作。 1)觸發器定義與作用:用於數據校驗、日誌記錄等。 2)工作原理:分為BEFORE和AFTER,支持行級觸發。 3)使用示例:可用於記錄薪資變更或更新庫存。 4)調試技巧:使用SHOWTRIGGERS和SHOWCREATETRIGGER命令。 5)性能優化:避免複雜操作,使用索引,管理事務。

在MySQL中創建和管理用戶賬戶的步驟如下:1.創建用戶:使用CREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';2.分配權限:使用GRANTSELECT,INSERT,UPDATEONmydatabase.TO'newuser'@'localhost';3.修正權限錯誤:使用REVOKEALLPRIVILEGESONmydatabase.FROM'newuser'@'localhost';然後重新分配權限;4.優化權限:使用SHOWGRA

MySQL適合快速開發和中小型應用,Oracle適合大型企業和高可用性需求。 1)MySQL開源、易用,適用於Web應用和中小型企業。 2)Oracle功能強大,適合大型企業和政府機構。 3)MySQL支持多種存儲引擎,Oracle提供豐富的企業級功能。

MySQL相比其他關係型數據庫的劣勢包括:1.性能問題:在處理大規模數據時可能遇到瓶頸,PostgreSQL在復雜查詢和大數據處理上表現更優。 2.擴展性:水平擴展能力不如GoogleSpanner和AmazonAurora。 3.功能限制:在高級功能上不如PostgreSQL和Oracle,某些功能需要更多自定義代碼和維護。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

禪工作室 13.0.1
強大的PHP整合開發環境

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!