Basic operation of Mac mysql database

1. Start, restart, stop, and view MySQL status
sudo /usr/local/mysql/support-files/mysql.server start
sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql /support-files/mysql.server restart
sudo /usr/local/mysql/support-files/mysql.server status
2. Reset password
If you do not use it for a long time, it is common to forget your password. . . A password reset is required at this point.

mysql -u root -p

3. Enter the database

/usr/local/MySQL/bin/mysql -u root -p

4. Query the database

show databases;

2. Connect to the remote database and enter the command line:

Suppose the IP of the remote host is: ip address, user name is root, password is 123456

1. Open the terminal and enter the following command:

mysql -h ip address -u root -p 123456

2. Enter the password:

The interface prompts to enter the password:

Enter password:

If it is the first time to use the database, the default password is empty, and you can enter the mysql command line directly by pressing Enter;

If a password has been set, enter the password and press Enter to enter the mysql command line.

3. Exit command: exit, press Enter to exit the mysql command line.

Four:

1. Create a database named NickYang create database NickYang character set utf8;

2. Modify the database encoding: alter database NickYang character set utf8;

3. Check whether the database is successfully created: show databases;

4. Enter the database: use NickYang;

5. Create a table and assign a primary key to the table: create table yang(id int primary key);

6. Check whether the table is created successfully: show tables;

7. View the table structure: desc table name;

8. Add field: alter table table name add field name data type [position];

alter  table yang add  name varchar(255) after id;

9. Delete field: alter table table name drop field name;

alter table yang drop name;

10. New data: insert into table name (field name) values ​​(value)

insert into  yang(id,name)  values(1,'name');

11. Delete data: delete from table name [where condition];

delete from yang [where id = 1]

12. Modify data: update table name set field = value [where condition]

update yang set name = 'yang' where id = 1;

13. Find data: select * from table name [where condition];

select * from yang [where id = 1];


 

Guess you like

Origin blog.csdn.net/xige1995/article/details/125371939