安裝環(huán)境如下所示:
Centos 7.4 64 位
Mysql 5.7
下載安裝MySQL Yum
ssh連接目標服務器后,用 wget 下載 5.7 版本的MySQL Yum
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
然后用 yum 安裝MySQL Yum
yum localinstall mysql57-community-release-el7-8.noarch.rpm
然后用命令檢測 MySQL Yum是否安裝成功
yum repolist enabled | grep "mysql.*-community.*"
安裝成功后你會看到下面的提示朝抖。
安裝 MySQL
yum install mysql-community-server
啟動 MySQL
systemctl start mysqld
//如此類推
systemctl stop mysqld
systemctl restart mysqld
//第二種奢人,容易記
service msyqld start
service msyqld stop
service msyqld restart
設置開機啟動 MySQL
systemctl enable mysqld
systemctl daemon-reload
修改 MySQL 密碼
因為安裝后,會自動給 root 生成默認密碼的较解,我們用下面命令查看密碼,5ejRwZBgquL就是默認密碼了。
[root@VM_65_249_centos ~]# grep 'temporary password' /var/log/mysqld.log
2018-06-13T04:04:42.144765Z 1 [Note] A temporary password is generated for root@localhost: #5ejRwZBgquL
登錄
mysql -u root -p
修改密碼
因為 mysql 設置了密碼安全檢查插件捆憎,你的密碼必須包含大小寫英文,數(shù)字梭纹,字符且不小于8位躲惰,需注意,以英文分號結束变抽。否則會報下面的錯础拨。
set password for 'root'@'localhost'=password('YourNewPassword123!');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements //不通過密碼安全插件檢查
遠程連接
因為 root 用戶默認禁止遠程連接,所以你可以改變策略讓 root 遠程連接绍载,或者創(chuàng)建新用戶去遠程連接诡宗。這里為了安全起見,新建用戶 ppjun
GRANT ALL PRIVILEGES ON *.* TO 'ppjun'@'%' IDENTIFIED BY 'YourNewPassword123!' WITH GRAN;
這里的意思是讓用戶 ppjun 分配本機所有數(shù)據(jù)庫所有表的權限击儡,并且設置密碼 YourNewPassword123!
配置默認 UTF8 編碼
vi /etc/my.cnf
在[mysqld]下面新增
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
然后在 mysql 里面看到編碼是utf8
mysql> show variables like '%character%';
+--------------------------+----------------------------+
| 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)
以上僚焦。