Install the database
When installing the database, we need to install three software. Using the following commands, there may be some problems. Regarding the installation of the database, you can go online and Baidu
yum install mysql
yum install mysql-server
yum install mysql-devel
- 1
- 2
- 3
My personal understanding is probably like this, we first need to install mysql in our own operating system, and then this mysql needs to provide services, so we need to install a server, and we need to connect the server to the database through the client operation
Start the server and connect to the server through the client
Start the server:
service mysqld start
- 1
Connect to the server through the client
mysql
- 1
If the following prompt is displayed, your client is already connected to the server
mysql>
- 1
After the above content, we can enter a command to manipulate the database.
==Note==: It should be noted that after entering this mode, each statement in the process of the database operation is;
Set password for root user
Exit the above client, we need to set a password for our root user to connect to the database
set password
mysqladmin -u root password "new_password"
- 1
The password I set by myself is neil1110
. When I log in with the root user, I can log in in the following way.
mysql -u root -p
- 1
After executing the above command, you will be prompted to enter a password, and then enter the password.
close the database
cd /usr/bin
- 1
./mysqladmin -u root -p shutdown
- 1
The system will prompt you to enter a password, you can enter the password at this time
Database user operations
If you need to add a MySQL user, you just need to add the new user to the user table in the mysql database.
The following is an example of adding a user, the user name is guest, the password is guest123, and the user is authorized to perform SELECT, INSERT and UPDATE operations
root@host# mysql -u root -p
Enter password:*******
mysql> use mysql;
Database changed
mysql> INSERT INTO user
(host, user, password,
select_priv, insert_priv, update_priv)
VALUES ('localhost', 'guest',
PASSWORD('guest123'),www.thylgw.cn/ 'www.wanmeiyuele.cn Y', www.mhylpt.com/ 'Y', www.thd178.com/ 'Y');
Query OK, 1 row affected (0.20 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 1 row affected (0.01 sec)
mysql> SELECT host,www.leyouzaixan.cn user, password FROM user WHERE user = 'guest'; +-----------+---------+------------------+ | host | user | password | +-----------+---------+------------------+ | localhost | guest | 6f8c114b58f2ce9e | +-----------+---------+------------------+ 1 row in set (0.00 sec)
Later we can use mysql -u guest -p, and then enter the password to log in to the server of the database
We can also add permissions for users when setting users. The specific permissions list is as follows
Select_priv
Insert_priv
Update_priv
Delete_priv
Create_priv
Drop_priv
Reload_priv
Shutdown_priv
Process_priv
File_priv
Grant_priv
References_priv
Index_priv
Alter_priv
We also have a second method for user operation of the database, which is to use the following method to set
root@host# mysql -u root -p password;
Enter password:*******
mysql> use mysql;
Database changed
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
-> ON TUTORIALS.*
-> TO 'zara'@'localhost' -> IDENTIFIED BY 'zara123'
Create a new database
in normal mode
mysqladmin -u root -p create HELLO
- 1
The above HELLO is the name of the database. Next, after we use the client to log in to the database, we can use
SHOW DATABASES;
- 1
To see what data we have created, here will show one of our HELLO databases
delete database
Be careful when deleting the database, because once the database is deleted, all our data will disappear. In the normal mode, delete the database in the following way
mysqladmin -u root -p drop HELLO
- 1
Select a database to operate
Entering the mysql> mode, that is, after successfully logging in using the client, we use the following statement to select a database for operation.
Assuming that my HELLO database has not been deleted