happy cat image

Start Web Coding

Your First step toward web coding,
Start Web Coding

change UI

Creating MySQL Account

This time, let's create a MySQL account. Create your own account, not root.
Please connect to MySQL. Then type the following statement, which means to see all created databases in MySQL.

SHOW DATABASES;
mysql image

Use the mysql database from the list of visible databases. To use a mysql database, use the statement use.

USE database name;

because you will be using mysql database. Please enter:

USE mysql;

Now let's look at the list of tables in the selected mysql database. The command to view a list of tables is show tables.

SHOW TABLES;
mysql image

If you look at the list of printed tables, you will see a table called user.
That table is used to create a new account.
To create a user account, you must connect to mysql as the root account !!
The database must also have a mysql database selected.
The account we will create is david with a password of 1234.
Let's take a look at the structure of the user table. The command to view the structure is desc.

DESC table name;

So the command to see the structure of the user table would be:

DESC user;

mysql> desc user; Check the structure of the user table. You can see the structure of the table with the desc command.
Then there are 39 fields in total. You have to set up all those 39 to create one account.

mysql image

So let's see what's in the user table.
To check, check the record in the user field.
To check a record, use the select command. Then write down the field to check.
Then we Let's look at three hosts, users, and passwords. You can see records for host, user, and password.

command

mysql> SELECT host, user, password FROM user;
mysql image

The password is encrypted because others can read the password of others in the same way.
Now let's create an account
The account we will create is david with a password of 1234.
You must fill in all 39 fields in the user table.
First select the mysql database.

USE mysql;

Then enter your account information INSERT INTO table name VALUES

insert into user values ('localhost', 'david', password('1234'),
'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y',
'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y',
'','','','',0,0,0,0);

This is the end. The above operation grants user access.
desc table name
If you don't do that, desc user; You need to check the number of enum ('N', 'Y') using the command and set the number.

mysql image

Then enter the following command to apply the changed user table to the mysql database system.

flush privileges;

We will also check if the david account is registered using host, user and password from user from the user table. (If you look at 39, there are too many, so check only the host, user and password fields.)

select host, user, password from user;
mysql image

It is registered as shown above !!
So let's access the account you created.
Type exit to exit
Let's connect again

mysql -udavid -p

Enter the password for the david account, 1234.

mysql image

Now let's delete the account
First create a new account to delete
Make it the same way as above. This time, create an account called honda.

insert into user values ('localhost', 'honda', password('1234'),
    'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y',
'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y',
'','','','',0,0,0,0);

After entering as above

SELECT host, user, password FROM user;

Enter the above command.

mysql image

The honda looks like the screen above.
Now let's delete this honda account
First select the mysql database.

use mysql;

Now let's delete the honda account.
Please enter the following statement:

DELETE FROM user WHERE user = 'honda';
flush privileges;
mysql image

As above, the honda account has been deleted.
This time, let's change the account password.
Exit mysql with exit and reconnect to the root account. You cannot change it unless you have a root account.

mysql -uroot -proot
update user set password=password('123456') where user='root';

And to apply

flush privileges;

Enter..

You write root at the top of the statement, but just write the name of the account you want to change. Then go to exit and test your login again.

강좌로 돌아가기