自從 CentOS 7 開始,自帶的數據庫就變成 MariaDB 了,yum 安裝之后的默認版本是 5.5
添加Maria源
添加並編輯文件
添加MariaDB源
vi /etc/yum.repos.d/MariaDB.repo
粘貼官方的或者阿里雲的鏡像:
[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.3/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
[mariadb] name = MariaDB baseurl = https://mirrors.aliyun.com/mariadb/yum/10.4/centos7-amd64/ gpgkey=https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck=1
2,安裝新版本的MariaDB
yum install mariadb mariadb-server
3,配置數據庫
啟動數據庫
systemctl start mariadb.service
第一次安裝,沒有密碼,直接進入數據庫
mysql -u root
設置初始密碼
mysql_secure_installation
[root]$ /usr/bin/mysql_secure_installation #輸入root(mysql)的密碼。默認沒有,直接回車 Enter current password for root (enter for none): #是否切換到unix套接字身份驗證[Y/n] Switch to unix_socket authentication [Y/n] n #是否設置root密碼 Change the root password? [Y/n] #如果選Y,就輸入2次密碼 New password: Re-enter new password: #是否刪除匿名用戶?(就是空用戶),建議刪除 Remove anonymous users? [Y/n] #是否不允許遠程root登錄 Disallow root login remotely? [Y/n] n #是否刪除test數據庫 Remove test database and access to it? [Y/n] n #是否加載權限使之生效 Reload privilege tables now? [Y/n] y
4,對數據庫的其他操作
停止
systemctl stop mariadb.service
重啟
systemctl restart mariadb.service
開機自啟
systemctl enable mariadb.service
參考:https://blog.csdn.net/qq_34691713/article/details/83896662