linux下mariadb安裝、配置
1.使用yum命令安裝mariaddb資料庫必須同時安裝mariadb-server
yum -y install mariadb mariadb-server
2.安裝完成後啟動mariadb資料庫
systemctl start mariadb
查看資料庫啟動狀態
systemctl status mariadb
出現"running"表示啟動成功
設置開機啟動
systemctl enable mariadb
3.資料庫的簡單配置
在Linux命令下直接執行mysql_secure_installation命令
首先設置密碼,提示先輸入密碼
Enter current password for root (enter for none):
設置密碼
Set root password? [Y/n]
New password:
Re-enter new password:
其他配置
Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n]
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]
初始化MariaDB完成,接下來測試登錄
運行mysql -u root -p命令輸入密碼
輸入密碼:
成功進入資料庫
4.配置MariaDB的字符集
設置客戶端:
vim /etc/my.cnf.d/mysql-clients.cnf
[mysql]
default-character-set=utf8
設置服務端:
vim /etc/my.cnf.d/server.cnf
[mysqld]
init_connect="SET collation_connection = utf8_general_ci"
init_connect="SET NAMES utf8"
character-set-server=utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake
#開啟慢查詢
slow_query_log = ON
slow_query_log_file = /usr/local/mysql/data/slow.log
long_query_time = 1
全部配置完成,重啟mariadb
systemctl restart mariadb
之後進入MariaDB查看字符集
在value列提示」utf8「表示設置成功
5. 添加用戶和許可權(在mariadb資料庫root的賬號下添加)
創建用戶命令create user "用戶名"@"許可權"identified by "密碼";
例如
mysql>create user "freedom"@"%" identified by "admin123";
mysql>flush privileges;刷新系統許可權表,否則用戶無法使用。
至此mariadb資料庫已完成安裝和配置,最後在執行
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT開啟3306埠,使shell可以正常連接到資料庫!此時只能使用用戶』freedom『登錄,要想使用root登錄,需要給root用戶授與遠程登錄許可權,需執行下面命令
mysql>GRANT ALL PRIVILEGES ON *.* TO "root"@"%" IDENTIFIED BY "my-new-password" WITH GRANT OPTION;
TAG:風靜樹止ZJ |