Mac MySQL initial password setting and MySQL basic operation

Table of contents

I. Introduction

Second, MySQL sets the initial password

3. MySQL basic commands

4. End


I. Introduction

This blog records the setting of the initial MySQL password and the basic operations of MySQL (building database, building table, inserting, querying) on ​​the Mac computer.

Second, MySQL sets the initial password

1. Step 1: In "System Preferences", close the MySQL service.

2. Enter the terminal command output: " cd /usr/local/mysql/bin/ " command, press Enter.

cd /usr/local/mysql/bin/

3. After pressing Enter, enter the command: " sudo su"  to log in with administrator privileges. Enter the data system password.

sudo su

4. Enter the following command to disable the mysql authentication function: “ ./mysqld_safe --skip-grant-tables & ” After pressing Enter, mysql will automatically restart (the status of mysql in the preferences will change to running).

./mysqld_safe --skip-grant-tables &

5. Enter the command ./mysql and press Enter.

./mysql

As shown above, steps 1, 2, and 3 correspond to steps 3, 4, and 5 above.

6. Enter the command: " FLUSH PRIVILEGES; " After pressing Enter, enter the command:

FLUSH PRIVILEGES;
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('你的新密码');

as the picture shows:

7. To log in to mysql, we need to enter " sudo su " in the terminal command to obtain super authority:

sudo su

After inputting, the super authority terminal displays sh-3.2#

Enter the local password (Apple ID password)

Then log in the code through the absolute path: " /usr/local/mysql/bin/mysql -u root -p "

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

Then enter the mysql password (my password is set to 123456) to log in successfully, as shown in the following figure:

3. MySQL basic commands

1. After the password is set, log in, and then view the database command:

show databases;

All default databases will be listed as follows:

2. Create a database

Let's create our own database with the following command:

create database my_db;

As follows:

3. Create a data table

Going into the database we just created, we then create a table in that database. Command as follows:

CREATE TABLE User
(
ID int NOT NULL AUTO_INCREMENT,
UserName varchar(255) NOT NULL,
Password varchar(255) NOT NULL,
PRIMARY KEY (ID)
);

As shown below:

4. Insert a row of data into the User table. Command as follows:

insert into User (UserName, Password) VALUES ('kongzhi', '123456');

As shown below:

5. View table

Then we need to look at the table below to see the data we just inserted into the table; the following command:

select * from User;

As shown below:

4. End

So far, the design of MySQL's initial password and some basic operations have been completed. If you think this article is helpful to you, don't let the blogger give it a thumbs up and bookmark it!

Guess you like

Origin blog.csdn.net/Wjhsmart/article/details/115737334