安裝步驟
1、安裝
可以通過 rpm -qa|grep mysql-server 查看是否已經(jīng)安裝mysql
下載并安裝MySQL官方的 Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server
默認的配置文件在/etc/my.cnf
2、字符集配置
執(zhí)行 vim /etc/my.cnf
添加配置,在[mysqld]節(jié)點下面添加:
default-character-set=utf8
character-set-server=utf8
注意:
5.1版本的mysql為了解決中文亂碼my.ini內(nèi)的[mysql]和[mysqld]中都寫
default-character-set=utf8
5.5版本[mysql]中可以寫default-character-set=utf8但是[mysqld]中要寫成character-set-server=utf8
然后 :wq 退出
3、自啟動配置
1)執(zhí)行chkconfig mysqld on
2)執(zhí)行chkconfig --list mysqld 查看,如果2-5位都是on 就是自啟動的
4、mysql服務(wù)器啟動
啟動mysql服務(wù):
service mysqld start(restart) 或者
/etc/rc.d/init.d/mysqld start
5、mysql初始化配置
因為還沒有設(shè)置密碼 所以執(zhí)行
mysql -u root 可以登錄到mysql服務(wù)中
1)查看目前mysql中的用戶
select user,host,password from mysql.user
2) 修改root密碼
set password for root@localhost=password('123456')
set password for root@127.0.0.1=password('123456')
3) exit 退出mysql
4)重新登錄mysql
mysql -u -root -p
- 刪除匿名用戶
查找匿名用戶
1)select user,host from mysql.user;
刪除
2) delete from mysql.user where user ='';
再次查看
3)select user,host from mysql.user;
刷新使操作生效
4)flush privileges;
7)插入一個用戶
insert into mysql.user (Host,User,Password) values ('localhost','yourname',password( 'yourpassword'))
使操作生效
flush privileges;
8)創(chuàng)建新的database
create datebase 'mydb' default character set utf8 collate utf8_general_ci;
9)給本地用戶授權(quán)
grant all privileges on mydb.* to yourname@localhost identified by 'yourpassword'
給你的用戶服氣mydb數(shù)據(jù)庫下所有的權(quán)限
10)給賬號開通外網(wǎng)的所有權(quán)限
某個數(shù)據(jù)庫
grant all privileges on mydb.* to yourname@'%' identified by 'yourpassword'
全部數(shù)據(jù)庫
grant all privileges on *.* to yourname@'%' identified by 'yourpassword'
或者
grant select,insert,update on mydb.* to yourname@'%' identified by 'yourpassword'
或
grant select,insert,update on mydb.t_test to yourname@'%' identified by 'yourpassword'
11、mysql 驗證
使用客戶端工具 鏈接測試即可
12、常用命令
啟動關(guān)閉重啟: sudo service mysqld start/stop/restart
登錄:mysql -u username -p