This article mainly introduces how to download and install mysql on MAC and configure the terminal environment.
1. Download the installation package
Network disk download: https://pan.baidu.com/s/1xxCE9-7ErAc6_U4QA_vFIA Password: ep84
Official website download: https://dev.mysql.com/downloads/mysql/
2. Double-click the downloaded installation package (.pkg file)
Keep clicking Continue. When the password setting interface appears midway, set and remember the password. This password is the root password for logging in to mysql.
4. After installation, open the system preferences and you will see the mysql icon.
Double-click to open and you will see the following page, which generally does not need to be modified.
5. Configure mysql in the terminal environment
1) Before configuration , enter in the terminal mysql
and find the following content, indicating that the terminal environment has not yet configured mysql.
2) Check whether mysql is installed , enter in the terminal: ls -al /usr/local/mysql/bin
3) Add the environment path: (the following shows the zsh environment)
a. Open the file: open ~/.zshrc
b. Add the statement: PATH=$PATH:/usr/local/mysql/bin
, and then save
c. Make the configured statement effective: source ~/.zshrc
if it is a bash environment , the above abc steps are:
a. Open the file: open ~/.bash_profile
b. Add statements: PATH=$PATH:/usr/local/mysql/bin
c. Make the configured statements take effect:source ~/.bash_profile
( Note : All the above steps a and b can also be edited through vim. zshrc or .bash_profile file)
4) The terminal environment is configured successfully . Enter: in the terminal and mysql
you can see the following information:
5) Log in and use mysql . Enter: mysql -uroot -p
, then enter the login password (root password) set during installation. After successful login, you can use mysql normally
. , mysql has been successfully installed!
6. The following introduces several common database operation syntaxes:
Simple operation of the database:
(1) Create database: create database 数据库名称;
(2) View database: show databases;
(3) Open database: use 数据库名称;
(4) Delete database:drop database 数据库名称;
Add, delete, and modify tables:
(1) Query data: select * from 表名 where 字段 = 值;
(2) Insert data: insert into 表名 (字段1, ……) values (值1, ……);
(3) Update data: update 表名 字段=值,…,字段n=值n where 字段=值;
(4) Delete data:delete from 表名 where 字段=值;