1. MySQL的安裝
本次學習基于CentOS7.3環(huán)境润歉,使用MySQL5.7
1.1下載4個rpm包
mysql-community-client-5.7.26-1.el7.x86_64.rpm
mysql-community-common-5.7.26-1.el7.x86_64.rpm
mysql-community-libs-5.7.26-1.el7.x86_64.rpm
mysql-community-server-5.7.26-1.el7.x86_64.rpm
從官網(wǎng)獲取以上4個rpm包地址模狭,直接下載(選擇合適的下載工具,然后上傳到CentOS7.3)
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-server-5.7.26-1.el7.x86_64.rpm
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-client-5.7.26-1.el7.x86_64.rpm
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-common-5.7.26-1.el7.x86_64.rpm
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-libs-5.7.26-1.el7.x86_64.rpm
1.2 安裝踩衩,先進入rpm包所在目錄
rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm
1.3 查看版本
[root@Centos7 mysql]# mysqladmin --version
mysqladmin Ver 8.42 Distrib 5.7.26, for Linux on x86_64
顯而易見嚼鹉,已經(jīng)成功安裝MySQL5.7。
2.MySQL的基本配置
2.1 設置免密登錄
2.1.1 修改配置文件免密碼登錄mysql
# 編輯配置文件
vim /etc/my.cnf
在 my.cnf 這個配置文件 [mysqld] 中加上如下語句 并保存退出文件九妈;
skip-grant-tables
跳過密碼驗證
重啟mysql服務
systemctl restart mysqld
2.1.2 免密登錄
mysql
# 或者
mysql -u root -p
# Password直接回車
2.1.3 給root用戶重置密碼
1)首先查看當前root用戶相關信息反砌,在mysql數(shù)據(jù)庫的user表中;
use mysql;
select host, user, authentication_string, plugin from user;
host: 允許用戶登錄的ip‘位置’%表示可以遠程萌朱;
user:當前數(shù)據(jù)庫的用戶名宴树;
authentication_string: 用戶密碼;在mysql 5.7.9以后廢棄了password字段和password()函數(shù)晶疼;
plugin: 密碼加密方式酒贬;
基本信息
2)如果當前root用戶authentication_string字段下有內(nèi)容,先將其設置為空翠霍;
update user set authentication_string='' where user='root';
3) 退出mysql锭吨,刪除/etc/my.cnf文件最后的 skip-grant-tables,重啟mysql服務寒匙;
4) 使用root用戶進行登錄零如,因為上面設置了authentication_string為空,所以可以免密碼登錄锄弱;
mysql
# 或者
mysql -u root -p
# Password直接回車
5) 使用ALTER修改root用戶密碼考蕾;
ALTER user 'root'@'localhost' IDENTIFIED BY 'Qian123#';
至此修改成功; 從新使用用戶名密碼登錄即可会宪;
2.2 MySQL的遠程連接授權
登錄mysql肖卧,執(zhí)行命令
# 允許遠程連接
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Qian123#' WITH GRANT OPTION;
2.3 MySQL字符集修改
vim /etc/my.cnf
在 my.cnf 這個配置文件 [mysqld] 中加入 character-set-server=utf8
,然后重啟mysql
字符集設為utf8
# 查看字符集
show VARIABLES like 'character%';
字符集
2.4 MySQL
# 查看大小寫是否敏感掸鹅,0 敏感塞帐,1 不敏感
show variables like '%lower_case_table_names%';
字符集設為utf8
在 my.cnf 這個配置文件 [mysqld] 中加入 lower_case_table_names = 1
拦赠,然后重啟服務器
大小寫不敏感