centos部署mysql-全方位解析資料庫安裝

部署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=utf8collation-server=utf8_general_ci[mysql]#下新增default-character-set=utf8

7、啟動mysql

systemctl start mysqld;

8、檢視啟動是否報錯

systemctl status mysqld

9、

【知識點】

登陸mysql,預設已建立如下四個庫。同時my。cnf中配置的datadir指定目錄下存在如下四個庫的資料夾。

centos部署mysql-全方位解析資料庫安裝

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

to

readonly

@

%

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 permissions2019-03-12T17:28:58。770928Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error2019-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返回NULLNO_AUTO_CREATE_USER:禁止GRANT建立密碼為空的使用者NO_ENGINE_SUBSTITUTION:如果需要的儲存引擎被禁用或未編譯,那麼丟擲錯誤。不設定此值時,用預設的儲存引擎替代,並丟擲一個異常PIPES_AS_CONCAT:將”||”視為字串的連線運算子而非或運算子,這和Oracle資料庫是一樣的,也和字串的拼接函式Concat相類似ANSI_QUOTES:啟用ANSI_QUOTES後,不能用雙引號來引用字串,因為它被解釋為識別符。

如果喜歡我的文章,請關注我哦。後續會提供更多的乾貨分享,請注意查收。