First, Login
Absolute path Login, terminal command:/usr/local/mysql/bin/mysql-u root-p
Change MySQL root account password Terminal input command:/usr/local/mysql/bin/mysqladmin-u root password new password
Second, create the user
@>mysql -u root -p@>密码
mysql>into mysql.user(Host,User,Password) values("localhost","changyou",password("changyou"));刷新系统权限表 mysql>flush privileges;这样就创建了一个名为:changyou 密码为:changyou 的用户。 然后登录一下。 mysql>exit; @>-u-p@>输入密码 mysql>
@>-u-p@>密码 mysql>WHERE User="phplamp"and Host="localhost";mysql>flush privileges;//删除用户的数据库 mysql>drop database phplampDB;
- Modifies the specified user password.
@>-u-p@>密码 mysql>update mysql.set password=password(‘新密码‘where User="phplamp"and Host="localhost";mysql>flush privileges;
Third, for the user authorization
1.
Grant all privileges in . to ' changyou ' @ '% ' with GRANT option;
Grant all privileges the ' changyou ' @ '% ' identified by ' changyou ';
Flush privileges;
2.
Grant all privileges the ' user ' @ ' localhost ' with GRANT option;
Grant all privileges the ' user ' @ ' localhost ' identified by ' 123456′;
Flush privileges;
Iv. creating a database for users
Log in to MySQL (with root privileges). I'm logged in as root..@>Mysql- uRoot- P@>Password first create a database for the user (CHANGYOUDB) MySQL>Create database changyoudb; Authorize the Changyou user to have all permissions to the CHANGYOUDB database. Grant AllPrivileges onChangyoudb.* to[Email protected] identified by ' Changyou '; Refresh System Permissions table MySQL>Flush Privileges;mysql>Other actions if you want to specify a partial permission to a user, you can write this: MySQL>GrantSelect, update onChangyoudb.* to[Email protected] identified by ' Changyou ';//Refresh the System permissions table. Mysql>Flush privileges;
V. Operational database
- Log in to the database as the root user @>mysql-u root-p
- Show all databases for current MySQL: show databases;
- Creating a new database: Create database name;
- Open a database: use database name;
- Show all data tables in the database: show tables;
- Create a new table: The CREATE TABLE table name (field name 1 data type, field Name 2 data type, ... If you want to set a primary key or non-null, add primary key (primary key) or not NULL after the data type
- Query data table: SELECT * from table name;
- Add record: INSERT into table name (Field 1, Field 2, ...) VALUES (' value 1 ', ' Value 2 ', ...);
- Delete Record: Delete from table name where query condition;
- Update record: The Update table name set field = new value where condition;
MySQL for Mac usage Summary