CentOS7後的版本,的yum源中默認好像是沒有mysql的。爲了解決這個問題,咱們要先下載mysql的repo源。html
1 # wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
安裝這個包後,會得到兩個mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。mysql
# yum install mysql-server
安裝完了,還須要一些基礎配置。sql
# systemctl enable mysqld #把mysql加入開機啓動
# systemctl start mysqld #啓動mysql服務進程
# mysql_secure_installation #配置mysql的密碼等
#[設置root用戶密碼]
Set root password? [Y/n] y
#[刪除匿名用戶]
Remove anonymous users? [Y/n] y
#[禁止root遠程登陸]
Disallow root login remotely? [Y/n] y
#[刪除test數據庫]
Remove test database and access to it? [Y/n] y
#[刷新權限]
Reload privilege tables now? [Y/n] y
# mysql -u root -p
mysql的配置文件爲/etc/my.cnf,加上編碼格式,否則有可能數據庫數據中文會亂碼:數據庫
[mysql] default-character-set =utf8
登陸mysql後,進行受權操做:編碼
-mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密碼' WITH GRANT OPTION;
使用iptables開放3306端口,才能夠遠程訪問。詳細請點擊這裏瞭解iptables的配置。spa
mysql經常使用命令:rest
啓用Mysql:
systemctl start mysqld
重啓Mysql: systemctl restart mysqld