安裝mariadb

centos7安裝mariadb

安裝

yum -y install mariadb mariadb-server

安裝完成MariaDB,首先啟動MariaDB

systemctl start mariadb

設(shè)置開機(jī)啟動

systemctl enable mariadb

MariaDB的相關(guān)簡單配置

  1. 初始化
mysql_secure_installation
  1. 首先是設(shè)置密碼,會提示先輸入密碼
Enter current password for root (enter for none):<–初次運(yùn)行直接回車
  1. 設(shè)置密碼
Set root password? [Y/n] <– 是否設(shè)置root用戶密碼,輸入y并回車或直接回車
New password: <– 設(shè)置root用戶的密碼
Re-enter new password: <– 再輸入一次你設(shè)置的密碼
  1. 其他配置
Remove anonymous users? [Y/n] <– 是否刪除匿名用戶,回車
Disallow root login remotely? [Y/n] <–是否禁止root遠(yuǎn)程登錄,回車
Remove test database and access to it? [Y/n] <– 是否刪除test數(shù)據(jù)庫,回車
Reload privilege tables now? [Y/n] <– 是否重新加載權(quán)限表,回車
  1. 初始化MariaDB完成,接下來測試登錄
mysql -uroot -ppassword

配置MariaDB的字符集

  1. 文件/etc/my.cnf
vi /etc/my.cnf
在[mysqld]標(biāo)簽下添加
init_connect='SET collation_connection = utf8_unicode_ci' 
init_connect='SET NAMES utf8' 
character-set-server=utf8 
collation-server=utf8_unicode_ci 
skip-character-set-client-handshake
  1. 文件/etc/my.cnf.d/client.cnf
vi /etc/my.cnf.d/client.cnf
在[client]中添加
default-character-set=utf8
  1. 文件/etc/my.cnf.d/mysql-clients.cnf
vi /etc/my.cnf.d/mysql-clients.cnf
在[mysql]中添加
default-character-set=utf8
  1. 全部配置完成,重啟mariadb
systemctl restart mariadb
  1. 進(jìn)入MariaDB查看字符集
mysql> show variables like "%character%";show variables like "%collation%";

顯示為

Variable_name Value
character_set_client utf8
character_set_connection utf8
character_set_database utf8
character_set_filesystem binary
character_set_results utf8
character_set_server utf8
character_set_system utf8
character_sets_dir /usr/share/mysql/charsets/

8 rows in set (0.00 sec)

Variable_name Value
collation_connection utf8_unicode_ci
collation_database utf8_unicode_ci
collation_server utf8_unicode_ci

3 rows in set (0.00 sec)

字符集配置完成。

添加用戶,設(shè)置權(quán)限

創(chuàng)建用戶命令

mysql>create user username@localhost identified by 'password';
直接創(chuàng)建用戶并授權(quán)的命令

mysql>grant all on \*.\* to username@localhost indentified by 'password';
授予外網(wǎng)登陸權(quán)限 

mysql>grant all privileges on \*.\* to username@'%' identified by 'password';
授予權(quán)限并且可以授權(quán)

mysql>grant all privileges on \*.\* to username@'hostname' identified by 'password' with grant option;
簡單的用戶和權(quán)限配置基本就這樣了。

其中只授予部分權(quán)限把 其中 all privileges或者all改為select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file其中一部分。

遠(yuǎn)程連接授權(quán):
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

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

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

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