Linux學(xué)習(xí)筆記(八):從MySQL 8.x到mysql Ver 15.1 Distrib 10.3.11-MariaDB

MySQL 配置

建立MySQL用戶及用戶組,方便單獨(dú)管理。因為這個用戶不需要直接登錄Linux系統(tǒng),所以無需設(shè)置密碼。

命令:groupadd mysql
命令:useradd -g mysql mysql
命令:usermod -g mysql mysql #可選
命令:groupadds mysql
查看:mysql -V

CentOS8 運(yùn)行MySQL失敗

啟動報錯:

[root@localhost singa]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@localhost singa]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Failed to start mysqld.service: Unit mysqld.service not found.
[root@localhost singa]# systemctl start mariadb.service
Failed to start mariadb.service: Unit mariadb.service not found.

問題排查:當(dāng)出現(xiàn)以上情況時,說明未安裝Mariadb.server,在啟動MySQL前會強(qiáng)制要求你啟動Mariadb.server進(jìn)行密碼等設(shè)置

Mariadb.server 使用yum等方式安裝失敗

[root@localhost singa]# yum install mariadb-server
上次元數(shù)據(jù)過期檢查:0:00:47 前,執(zhí)行于 2019年11月05日 星期二 15時15分58秒。
錯誤:
問題: problem with installed package mysql-8.0.17-3.module_el8.0.0+181+899d6349.x86_64

  • package mysql-8.0.17-3.module_el8.0.0+181+899d6349.x86_64 conflicts with mariadb provided by mariadb-3:10.3.11-2.module_el8.0.0+35+6f2527ed.x86_64
  • package mariadb-3:10.3.11-2.module_el8.0.0+35+6f2527ed.x86_64 conflicts with mysql provided by mysql-8.0.17-3.module_el8.0.0+181+899d6349.x86_64
  • package mariadb-server-3:10.3.11-2.module_el8.0.0+35+6f2527ed.x86_64 requires mariadb(x86-64), but none of the providers can be installed
  • conflicting requests
  • package mysql-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64 is excluded
    (try to add '--allowerasing' to command line to replace conflicting packages or '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

問題排查:當(dāng)出現(xiàn)以上情況時,說明使用過yun install mysql這一命令安裝過mysql,或者使用過LNMP等集成環(huán)境包,這些安裝包沒有及時更新mariadb-server服務(wù),所以連接服務(wù)失效。mariadb-server服務(wù)類似于安裝向?qū)?,用來配置簡單的安全信息,CentOS環(huán)境下,MySQL-8.0強(qiáng)制優(yōu)先配置。

解決辦法:CentOS已提供支持

We already supply both mysql and mariadb in the repos.
查看軟件包命令:dnf list mysql-server mariadb-server
「嘗試在命令行中添加『--allowerasing』以替換有沖突的軟件包,或者『skip-broken』以跳過可卸載的軟件包,或者『 --nobest』不僅使用最佳候選軟件包」
安裝命令:yum install mysql-server
安裝命令:yum install mariadb-server --allowerasing

在補(bǔ)充完這兩個軟件包之后,MySQL和Mariadb即刻正常配置。


執(zhí)行MySQL安全配置向?qū)?/h3>

命令:systemctl start mariadb.service
命令:systemctl enable mariadb.service
命令:mysql_secure_installation

[root@localhost singa]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Enter current password for root (enter for none): #初次運(yùn)行直接回車
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
# 以下全部選Y
Set root password? [Y/n] Y
New password: # 設(shè)置root用戶密碼
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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.

Remove anonymous users? [Y/n] 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.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB 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? [Y/n] 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? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

啟動命令:systemctl start mysql.service
查看啟動狀態(tài):systemctl status mysqld.service
按q退出

[root@localhost singa]# mysql -V
mysql  Ver 15.1 Distrib 10.3.11-MariaDB, for Linux (x86_64) using readline 5.1

我懵了。

啊啊不管了,詳細(xì)配置信息,請看: Configuring MariaDB with Option Files

參考

MySQL無法啟動

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容