MySQL for MAC installation and basic operations

Source: Internet
Author: User
Tags mysql download administrator password

one. Install MySQL


1.mysqlhttp://dev.mysql.com/downloads/mysql/my machine is Mac 10.8, so use MYSQL-5.6.10-OSX10.7-X86_64.DMG to install the package;
2. The installation package is located in the hard drive image (. dmg) file, you must first double-click the icon in the search to install the file. You should install the image and display its contents.

Note: Be sure to close all running MySQL server instances using the MySQL Manager application (on Mac OS x server) or mysqladmin shutdown on the command line before continuing with the installation.
MySQL's Mac OS X pkg is installed to/usr/local/mysql-version, and a symbolic connection is also installed,/usr/local/mysql, pointing to the new location. If you have a/usr/local/mysql directory, rename it to/usr/local/mysql.bak first. When the installation is complete, the installer executes mysql_install_db to create the authorization table in the MySQL database.

The installation layout is similar to the tar file binary distribution; All MySQL binaries are in directory/usr/local/mysql/bin. By default, the MySQL socket file is created as/tmp/mysql.sock.

There are two ways to install MySQL under Mac, one forCompressed Package Formanother type of. dmg File Installation package.

First, we introduce the installation method of the compressed package form:

$ sudo mv mysql-5.1.45-osx10.6-x86_64 /usr/local/mysql
$ cd /usr/local
$ sudo chown -R mysql:mysql mysql
$ cd mysql
$ sudo scripts/mysql_install_db --user=mysql
$ sudo chown -R root .
$ sudo chown -R mysql data

Then CD bin with
$ sudo ./mysql_secure_installation
To modify the root password, which is empty by default, is obviously less secure, and is then configured as appropriate, as the development environment is less restrictive.

$ sudo ./mysqld_safe
To start MySQL

$ sudo ./mysql -u root -p
Enter the root password you just set to log in to MySQL

$ sudo ./mysqld_safe stop
Stop MySQL


Installation package file Form installation method:

First, go to http://www.mysql.com/downloads/mysql download mysql-5.6.10-osx10.7-x86_64.dmg, and then double-click the file to install the two installation package files in the image.

A. mysql-5.6.10-osx10.7-x86_64.dmg(MySQL Standard Edition installation)

B. mysqlstartupitem.pkg (MySQL startup project), you can automatically run the MySQL service when your computer starts the system, it installs in/library/startupitems/mysql/, if you do not want to run the MySQL service when the system starts, Please do not install. If you do not want to use it after installation, please delete the/library/startupitems/mysql/directory.

Start the MySQL service

1, if you have installed the MYSQLSTARTUPITEM.PKG, restart the computer.

2, if you have installed mysqlstartupitem.pkg or do not want to start the computer, run: application-utility-terminal, enter command in Terminal: sudo/library/startupitems/mysqlcom/mysqlcom start , then enter your system administrator password.

Turn off MySQL service

Enter the command in Terminal: sudo/library/startupitems/mysqlcom/mysqlcom stop, then enter your system administrator password.

You can also go to System Preferences-other-mysql, through which to start and stop the MySQL service.

Change the MySQL root account password

Terminal input command:/usr/local/mysql/bin/mysqladmin-u root password new password

You can change your password at any time by using this command.

Terminal login MySQL

Terminal Login MySQL

Method 1: Absolute path

Terminal input Command:/usr/local/mysql/bin/mysql- u root-p

Tip: Enter your new password


Method 2: (recommended) relative path

Enter the command in the terminal:

To see if there is a path in the path:

Input command in terminal: Echo $PATH

No, go ahead.

Add Required path: path= "$PATH":/usr/local/mysql/bin

later

you need to enter a command in the terminal: MySQL - u root-p can be



Two. Create User assignment permissions
Grant all privileges on * * to ' user ' @ ' localhost ' with GRANT option
Grant all privileges on * * to ' user ' @ ' localhost ' identified by ' 123456′;
Flush privileges;

1. Create a new user.

Log in to MySQL
@>mysql-u root-p
@> Password
Create user
mysql> INSERT INTO Mysql.user (Host,user,password) VALUES ("localhost", "Phplamp", Password ("1234"));
Refresh System Permissions Table
Mysql>flush privileges;
This creates a user named: Phplamp with a password of: 1234.

Then log in.

mysql>exit;
@>mysql-u phplamp-p
@> Enter password
Mysql> Login Successful

2. Authorize the user.

Log in to MySQL (with root privileges). I am logged in as root.
@>mysql-u root-p
@> Password
First create a database for the user (phplampdb)
Mysql>create database phplampdb;
Authorizes the Phplamp user to have all the permissions of the Phplamp database.
>grant all privileges in phplampdb.* to [e-mail protected] identified by ' 1234 ';
Refresh System Permissions Table
Mysql>flush privileges;
Mysql> Other operations


If you want to specify partial permissions to a user, you can write:
Mysql>grant select,update on phplampdb.* to [e-mail protected] identified by ' 1234 ';
Refreshes the System permissions table.
Mysql>flush privileges;


3. Delete the user.
@>mysql-u root-p
@> Password
Mysql>delete from user WHERE user= "phplamp" and host= "localhost";
Mysql>flush privileges;
Delete a user's database
Mysql>drop database phplampdb;

4. Modify the specified user password.
@>mysql-u root-p
@> Password
Mysql>update Mysql.user Set Password=password (' New password ') where user= "Phplamp" and host= "localhost";
Mysql>flush privileges;


MySQL for MAC installation and basic operations

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.