Centos 7 yum 安裝mariadb

1、mariadb安裝

[root@localhost ~]# yum -y install mariadb mariadb-server

#安裝完成後啓動mariadb並添加到自啓動
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl enable mariadb


#mariadb設置:root密碼等
[root@localhost ~]# mysql_secure_installation
1、設置密碼,首次進入無密碼,直接回車
Enter current password for root (enter for none): 回車
OK, successfully used password, moving on...

2、設置root密碼
Set root password? [Y/n] y
New password: 輸入root密碼
Re-enter new password: 輸入root密碼
Password updated successfully!
Reloading privilege tables..
 ... Success!

3、是否刪除匿名用戶
Remove anonymous users? [Y/n] 回車
 ... Success!
4、是否禁止root遠程登錄
Disallow root login remotely? [Y/n]
 ... Success!
5、是否刪除test數據庫
Remove test database and access to it? [Y/n]
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
6、是否重新加載權限表
Reload privilege tables now? [Y/n]
 ... Success!

Cleaning up...

mariadb安裝完成,使用mysql -uroot -p登錄測試

 

2、mariadbz字符集配置

修改/etx/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,在[client]中添加

default-character-set=utf8

修改/etc/my.cnf.d/mysql-clients.cnf,在[mysql]中添加

default-character-set=utf8

重啓mariadb

[root@localhost ~]# systemctl restart mariadb

進入mariadb查看字符集

MariaDB [(none)]> show variables like "%character%";show variables like "%collat              ion%";
+--------------------------+----------------------------+
| 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.01 sec)

3、用戶、權限設置

配置root允許遠程訪問

MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'root' WITH GRANT OPTION;
Query OK, 0 rows affected (0.03 sec)

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

創建用戶命令

create user username@localhost identified by 'password';


直接創建用戶並授權的命令

grant all privileges on *.* to test@'%' identified by 'test';


授予外網登陸權限 

grant all privileges on *.* to username@'%' identified by 'password';


授予權限並且可以授權

grant all privileges on *.* to username@'192.168.100.200' identified by 'password' with grant option;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章