MySQL for Mac usage Summary

Source: Internet
Author: User

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

    • Log in to MySQL
@>mysql -u root -p@>密码 
    • Create user
mysql>into mysql.user(Host,User,Password) values("localhost","changyou",password("changyou"));刷新系统权限表 mysql>flush privileges;这样就创建了一个名为:changyou  密码为:changyou 的用户。 然后登录一下。 mysql>exit; @>-u-p@>输入密码 mysql>
    • Delete the user.
@>-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

    1. Log in to the database as the root user @>mysql-u root-p
    2. Show all databases for current MySQL: show databases;
    3. Creating a new database: Create database name;
    4. Open a database: use database name;
    5. Show all data tables in the database: show tables;
    6. 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
    7. Query data table: SELECT * from table name;
    8. Add record: INSERT into table name (Field 1, Field 2, ...) VALUES (' value 1 ', ' Value 2 ', ...);
    9. Delete Record: Delete from table name where query condition;
    10. Update record: The Update table name set field = new value where condition;

MySQL for Mac usage Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.