Mac MySQL Installation

Source: Internet
Author: User

First, install MySQL

1, to the MySQL official online http://dev.mysql.com/downloads/mysql/, download MySQL can install DMG version

Take 5.7.14 for example: Mac OS X 10.11 (x86, 64-bit), DMG Archive

The downloaded files are: mysql-5.7.14-osx10.11-x86_64.dmg

2, double-click the downloaded mysql-5.7.14-osx10.11-x86_64.dmg file, appear, double-click Mysql-5.7.14-osx10.11-x86_64.pkg, to install.

The final step of the installation, you must be aware of the pop-up box, do not take the risk of clicking.

3, pop-up box appears, be sure to remember the contents of the red box, because this is the default password MySQL, is randomly generated.

If you accidentally click "OK", do not remember the password is not related to open the top right corner of the desktop "notification", MySQL will notify the password in the notification. I've been stuck here for a long time. Watch out! Watch out! Watch out!

4, after successful installation, open "System Preferences", the bottom will appear, that is, the installation is successful.

5. Click on the MySQL icon to appear, then click "Start MySQL Server" to start MySQL.

This is the successful start of MySQL.

Second, open the terminal, define MySQL aliases

Enter the alias command: Alias Mysql=/usr/local/mysql/bin/mysql

Enter, then input: Alias Mysqladmin=/usr/local/mysql/bin/mysqladmin

Third, set the MySQL root account of the secret (the initial password is one, 3 mentioned in the Oh!!!) ) (may be skipped)

mysqladmin-u Root Password initial password

2. If you have finished setting the password, you need to modify it, execute the command

Mysqladmin-u root-p Password

After executing the change Password command, enter the old password once, and then enter the new password two times as shown in.

Iv. Connecting the database

Mysql-u root-p

Then prompt for a password, enter the initial password set in the three

Prompt when finished typing


2. If you log in to the MySQL database on the remote host

Mysql-h host Address-u user name-P user Password

V. Perform common MySQL database operations

Note: The following actions are sent now, after connecting to the database, enter the MySQL environment, then execute the command must have a semicolon ";"

First, connect mysql:mysql-u root-p with root privileges

Then, enter the root password

1. Add new users

The format is as follows:

Grant operation permissions on the database. * To username @ Login host address identified by ' password ';

Grant, a user on a host (with the user's login password) on a database, perform certain actions permissions

(1) For example: on any host ("%"), the user (user name: test1, Password: ADC) on all databases, perform arbitrary operation permissions (very dangerous)

Grant all privileges on * * to [email protected] '% ' identified by ' ABC ';

Where all privileges means query, insert, modify, delete permissions: Select,insert,update,delete

The above command is equivalent to:

Grant Select,insert,update,delete on * * to [e-mail protected] "%" identified by "ABC";

And then refresh the permissions

Flush privileges;

(2) For example: permission to authorize the user to operate the database on the local host

Create a database (for example: OpenFire)

Create Database OpenFire;

Grant Local Host User (user name: test2, Password: 123) Access database (database name: openfire) Operation permissions

Grant all privileges the openfire.* to [e-mail protected] identified by "123";

Flush privileges;

After that, you can access the OpenFire database with a new user.

2. Update the password for the specified account (user name: Test1, New password: 1234)

Update Mysql.user set Password=password (' 1234 ') where user= "Test1" and host= "localhost";

3. Delete a user

Use MySQL Database First

Use MySQL;

Delete a local user (TEST7) from the user table in the MySQL database

Delete from user where user= "test7" and host= "localhost";

4. Show commands

(1) Show list of all databases: show databases;

Initialize only two databases, MySQL and test

Note: MySQL's system information is stored in the MySQL library, such as: Change Password and new users, is actually using this library to operate

(2) Open a database (e.g. database: Open fire): use OpenFire;

(3) Show all tables in this library: show tables;

(4) Display the structure of a table (table1): describe table1;

(5) Build database: Create database name;

(6) Build table:

Use library name;

CREATE TABLE table name (field settings list);

(7) Delete library: drop database name;

(8) Delete table: The name of the drop table;

(9) Empty the records in the table: Delete from table name;

(10) display the records in the table: SELECT * from table name;

Vi. quitting MySQL

Exit

Seven, start and stop MySQL

Start

/usr/local/mysql/share/mysql.server start

Stop it

/usr/local/mysql/bin/mysqladmin-u root-p shutdown

Enter the root password

Mac MySQL Installation

Related Article

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.