how to use mysql on mac
1.开启远程连接(非mysqld -h localhost -u *登录)
1)改表法
use mysql;
update user set host = '%' where user = 'root';
select host, user from user where user = 'root';
2)授权法
用户root使用123456密码从任何主机连接到mysql服务器:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;
用户root使用123456密码从ip为192.168.1.128的主机连接到mysql服务器:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.128' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;
用户root使用123456密码从ip为192.168.1.128的主机连接到mysql服务器的test数据库:
GRANT ALL PRIVILEGES ON test.* TO 'root'@'192.168.1.128' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;
2.
mysql启动:/usr/local/mysql/bin/mysqld_safe --user=Eric & # sudo /usr/local/mysql/bin/mysqld_safe --console
mysql停止:sudo /usr/local/mysql/bin/mysqld_safe stop # sudo /usr/local/mysql/bin/mysqladmin -u root shutdown
更改mysql root账户密码:/usr/local/mysql/bin/mysqladmin -u root 新密码
[/usr/local/mysql/bin/mysqld -h localhost -u root -proot]创建用户|分配权限:
grant all privileges on *.* to 'user'@'localhost' with grant option
grant all privileges on *.* to 'user'@'localhost' identified by '123456′;
# 授权test用户拥有testdb数据库的所有权限。
grant all privileges on testdb.* to test@localhost identified by '123456';
grant select,update on testdb.* to test@localhost identified by '123456';
flush privileges;
新建用户:
insert into mysql.user(Host,User,Password) values("localhost","test",password("123456"));
flush privileges;
删除用户:
DELETE FROM user WHERE User="test" and Host="localhost";
flush privileges;
修改指定用户密码:
update mysql.user set password=password('新密码') where User="test" and Host="localhost";
flush privileges;
3.mac创建组及分配
sudo dscl . -list /groups GroupMembership
sudo dscl . -list /Groups PrimaryGroupID
sudo dscl . create /Groups/mysql PrimaryGroupID 403
sudo dscl . -append /Groups/mysql GroupMembership Eric
/usr/local/mysql/my.cnf
http://www.ntu.edu.sg/home/ehchua/programming/sql/MySQL_HowTo.html