一. 终端登录mysql
方法1:绝对路径
终端中输入命令:/usr/local/mysql/bin/mysql
提示:输入你的新密码
方法2:(推荐)相对路径
终端中输入命令:set
查看路径中有没有需要的路径;
或者终端中输入命令:echo $PATH
没有,继续
添加需要路径:PATH="$PATH":/usr/local/mysql/bin
以后: export PATH
终端中需输入命令:mysql
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>
二. 创建用户 分配权限
登录MYSQL
>mysql -u root -p
@>密码
创建用户
mysql> insert into mysql.user(Host,User,Password) values("localhost","phplamp",password("1234"));
刷新系统权限表
mysql>flush privileges;
这样就创建了一个名为:phplamp
然后登录一下。
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;