序
由于Mysql已被Oracle收購吴侦,CentOS7默認可以安裝MarialDB 5.5.2双泪,如果要安裝最新的版本,需要自己設置安裝源吉殃,本文主要針對默認版本辞居。
su -
rpm -qa | grep mariadb
yum remove mysql mysql-server mysql-libs compat-mysql51
rpm -e --nodeps mariadb-*
vim /etc/yum.repos.d/MariaDB.repo
# MariaDB 10.1 CentOS repository list - created 2017-02-15 20:31 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
yum -y install MariaDB-server MariaDB-client
安裝
yum -y install mariadb mariadb-server
#安裝完成MariaDB,首先啟動MariaDB
systemctl start mariadb
#設置開機啟動
systemctl enable mariadb
#接下來進行MariaDB的相關(guān)簡單配置
mysql_secure_installation
#首先是設置密碼蛋勺,會提示先輸入密碼
Enter current password for root (enter for none):<–初次運行直接回車
#設置密碼
Set root password? [Y/n] <– 是否設置root用戶密碼瓦灶,輸入Y并回車或直接回車
New password: <– 設置root用戶的密碼
Re-enter new password: <– 再輸入一次你設置的密碼
其他配置
Remove anonymous users? [Y/n] <– 是否刪除匿名用戶,輸入Y并回車
Disallow root login remotely? [Y/n] <–是否禁止root遠程登錄,輸入n并回車,
Remove test database and access to it? [Y/n] <– 是否刪除test數(shù)據(jù)庫迫卢,回車
Reload privilege tables now? [Y/n] <– 是否重新加載權(quán)限表倚搬,回車
#初始化MariaDB完成冶共,接下來測試登錄
mysql -h127.0.0.1 -uroot -p
完成乾蛤。
配置MariaDB的字符集
#文件/etc/my.cnf
vi /etc/my.cnf
#在[mysqld]標簽下添加
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
#文件/etc/my.cnf.d/client.cnf
vi /etc/my.cnf.d/client.cnf
#在[client]中添加
default-character-set=utf8
#文件/etc/my.cnf.d/mysql-clients.cnf
vi /etc/my.cnf.d/mysql-clients.cnf
#在[mysql]中添加
default-character-set=utf8
#全部配置完成,重啟mariadb
systemctl restart mariadb
#進入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)
MariaDB [mysql]> select version();
+----------------+
| version() |
+----------------+
| 5.5.52-MariaDB |
+----------------+
1 row in set (0.00 sec)
添加用戶捅僵,設置權(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其中一部分。