-
-
Save danhantao/e06c06ddae93721f89f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.mysql 默认不允许其他主机访问。 | |
修改配置。vi /etc/mysql/my.cnf | |
把bind-address = 127.0.0.1 or localhost 注掉 | |
service mysql restart or init.d/mysql restart | |
2.添加用户 | |
mysql 中的用户对应的表是 database:mysql,table:user | |
insert into mysql.user(Host,User,Password) values('localhost','phplamp',password('1234')); | |
host 代表可以访问的主机。如果允许所有主机访问则为% | |
2. 授权。例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。 | |
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'benjamin' WITH GRANT OPTION; | |
如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码 | |
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; | |
GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.10.40.54' IDENTIFIED BY '123456' WITH GRANT OPTION; | |
撤销权限 | |
revoke all on *.* from dba@localhost; | |
or 直接删user表中的对应数据 (谨慎使用) | |
flush privileges; | |
查看权限 | |
查看当前用户(自己)权限: | |
show grants; | |
查看其他 MySQL 用户权限: | |
show grants for dba@localhost; | |
mysql默认安装的编码可能是: | |
Server characterset: latin1 | |
Db characterset: latin1 | |
Client characterset: utf8 | |
Conn. characterset: utf8 | |
下面我们设置mysql 字符集 charset | |
vi /etc/mysql/my.cnf | |
在[mysqld]下面加入一行 | |
character_set_server = utf8 | |
在[mysql]下面加入一行 | |
default-character-set = utf8 | |
server mysqld restart | |
mysql -uroot -p | |
mysql>status; | |
Server characterset: utf8 | |
Db characterset: utf8 | |
Client characterset: utf8 | |
Conn. characterset: utf8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment