Mac OS下的Mysql的基本操作

一. 终端登录mysql


方法1:绝对路径

终端中输入命令:/usr/local/mysql/bin/mysql -u root -p

提示:输入你的新密码


方法2:(推荐)相对路径

终端中输入命令:set

查看路径中有没有需要的路径;

或者终端中输入命令:echo $PATH

没有,继续

添加需要路径:PATH="$PATH":/usr/local/mysql/bin

以后: export PATH

终端中需输入命令:mysql -u root -p 即可,这样就可以连接上数据库了。

localhost:~ user$ /usr/local/mysql/bin/mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 32
Server version: 5.5.52 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 




创建用户 分配权限 


1.新建用户。 

登录MYSQL 
>mysql -u root -p 
@>密码 
创建用户 
mysql> insert into mysql.user(Host,User,Password) values("localhost","phplamp",password("1234")); 
刷新系统权限表 
mysql>flush privileges; 
这样就创建了一个名为:phplamp   密码为:1234   的用户。 

然后登录一下。 

mysql>exit; 
@>mysql -u phplamp -p 
@>输入密码 
mysql>登录成功 

2.为用户授权。 

登录MYSQL(有ROOT权限)。我里我以ROOT身份登录. 
@>mysql -u root -p 
@>密码 
首先为用户创建一个数据库(phplampDB) 
mysql>create database phplampDB; 
授权phplamp用户拥有phplamp数据库的所有权限。 
>grant all privileges on phplampDB.* to phplamp@localhost identified by '1234'; 
刷新系统权限表 
mysql>flush privileges; 
mysql>其它操作 


如果想指定部分权限给一用户,可以这样来写: 
mysql>grant select,update on phplampDB.* to phplamp@localhost identified by '1234'; 
//刷新系统权限表。 
mysql>flush privileges; 


3.删除用户。 
@>mysql -u root -p 
@>密码 
mysql>DELETE FROM user WHERE User="phplamp" and Host="localhost"; 
mysql>flush privileges; 
//删除用户的数据库 
mysql>drop database phplampDB; 

4.修改指定用户密码。 
@>mysql -u root -p 
@>密码 
mysql>update mysql.user set password=password('新密码') where User="phplamp" and Host="localhost"; 

mysql>flush privileges; 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值