部署mysql5.7.25
1、下載rpm安裝包。
2、上傳到伺服器,解壓。
3、卸載之前的版本。
4、按照順序安裝:
rpm -ivh mysql-community-common-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.25-1.el7.x86_64.rpm
5、修改配置文件為無需密碼登陸
vi /etc/my.cnf
[mysqld]#下添加
skip-grant-tables=1 #不用驗證,無需密碼登陸
6、修改默認字符集為utf8
vi /etc/my.cnf
[mysqld]#下添加
character-set-server=utf8
collation-server=utf8_general_ci
[mysql]#下添加
default-character-set=utf8
7、啟動mysql
systemctl start mysqld;
8、查看啟動是否報錯
systemctl status mysqld
9、【知識點】登陸mysql,默認已創建如下四個庫。同時my.cnf中配置的datadir指定目錄下存在如下四個庫的文件夾。

10、修改密碼
mysql>use mysql
mysql>update user set
mysql>authentication_string=password(『123456』) ,
mysql>password_expired=『N』,password_last_changed=now()
mysql>where user=『root』;
mysql>flush privileges;
mysql> alter user 『root』@『localhost』 identified by 『123456』;
mysql>Flush privileges;
mysql>exit;
同時my.cnf 刪除參數skip-grant-tables=1,
重啟mysql:systemctl restart mysqld 。
11、測試是否可用
mysql -uroot -p -e 「show databases;」;–安全起見-p不加密碼
12、配置可被其他主機訪問
新增host為『%』的用戶:
create user readonly@% identified by』readonly』;
grant select on . toreadonly@%;
13、確認網路連通的前提,開放防火牆埠
firewall-cmd –zone=public –add-port=3306/tcp –permanent
14、重新啟動防火牆
firewall-cmd –reload
卸載mysql5.7.25
1、卸載程序:由於存在依賴關係,故需要按如下順序卸載
rpm -e mysql-community-server-5.7.25-1.el7.x86_64
rpm -e mysql-community-devel-5.7.25-1.el7.x86_64
rpm -e mysql-community-client-5.7.25-1.el7.x86_64
rpm -e mysql-community-libs-5.7.25-1.el7.x86_64
2、清除余項
whereis mysql
rm -rf 相關文件
3、刪除配置文件
rm -rf /etc/my.cnf*
4、刪除默認datadir路徑
rm –rf /var/lib/mysql
5、剩餘配置檢查:(此次操作如下無結果)
chkconfig –list | grep -i mysql
chkconfig –del mysql
問題鑒賞
1、關閉selinux
報錯:
2019-03-12T17:28:58.770891Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2019-03-12T17:28:58.770912Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
2019-03-12T17:28:58.770918Z 0 [ERROR] InnoDB: os_file_get_status() failed on './ibdata1'. Can't determine file permissions
2019-03-12T17:28:58.770928Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2019-03-12T17:28:59.371503Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2019-03-12T17:28:59.371548Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2019-03-12T17:28:59.371556Z 0 [ERROR] Failed to initialize builtin plugins.
2019-03-12T17:28:59.371560Z 0 [ERROR] Aborting
解決方法:
查看selinux狀態:getenforce。
關閉selinux:setenforce 0。
2、修改密碼後show databases報錯
mysql>Update mysql.user set authentication_string=password(『* * *』) where user=』root』;
mysql>Flush privileges;
此時訪問均正常。
退出mysql,配置文件my.cnf 刪除參數skip-grant-tables=1,重啟mysql可使用密碼重新登陸。
登陸後執行指令:
show databases;
報錯ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executin。
解決方法:
mysql>alter user 『root』@『localhost』 identified by 『****』;
mysql>Flush privileges;
mysql>show databases;
3、sql_mode參數賞析
my.cnf新增配置信息sql_mode=;重啟mysql。
ONLY_FULL_GROUP_BY:出現在select語句、HAVING條件和ORDER BY語句中的列,必須是GROUP BY的列或者依賴於GROUP BY列的函數列。
NO_AUTO_VALUE_ON_ZERO:該值影響自增長列的插入。默認設置下,插入0或NULL代表生成下一個自增長值。如果用戶希望插入的值為0,而該列又是自增長的,那麼這個選項就有用了。
STRICT_TRANS_TABLES:在該模式下,如果一個值不能插入到一個事務表中,則中斷當前的操作,對非事務表不做限制
NO_ZERO_IN_DATE:這個模式影響了是否允許日期中的月份和日包含0。如果開啟此模式,2016-01-00是不允許的,但是0000-02-01是允許的。它實際的行為受到 strict mode是否開啟的影響1。
NO_ZERO_DATE:設置該值,mysql資料庫不允許插入零日期。它實際的行為受到 strictmode是否開啟的影響2。
ERROR_FOR_DIVISION_BY_ZERO:在INSERT或UPDATE過程中,如果數據被零除,則產生錯誤而非警告。如果未給出該模式,那麼數據被零除時MySQL返回NULL
NO_AUTO_CREATE_USER:禁止GRANT創建密碼為空的用戶
NO_ENGINE_SUBSTITUTION:如果需要的存儲引擎被禁用或未編譯,那麼拋出錯誤。不設置此值時,用默認的存儲引擎替代,並拋出一個異常
PIPES_AS_CONCAT:將」||」視為字元串的連接操作符而非或運算符,這和Oracle資料庫是一樣的,也和字元串的拼接函數Concat相類似
ANSI_QUOTES:啟用ANSI_QUOTES後,不能用雙引號來引用字元串,因為它被解釋為識別符。
原創文章,作者:投稿專員,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/233150.html