Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Simply master the operation method of mysql

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly gives you a brief introduction to the operation of mysql. You can check the relevant professional terms on the Internet or find some related books to supplement them. We will not dabble here, so let's go straight to the topic. I hope this article on the operation of mysql can bring you some practical help.

# # simple Operation of mysql #

# it usually ends with ";" in mysql.

(1) yum install mariadb-server-y # # install the software

Systemctl start mariadb # # enable the service

Mysql_secure_installation # # install mysql for the first time, because you don't have a password when you first enter mysql. You can use this > command to operate on mysql and add a password.

Mysql-u root-predhat # # enter mysql as a super user and redhat when using the password

SHOW DATABASES; # # display database

SHOW TABLES; # # display table

USE mysql; # # enter mysql database

SETECT * FROM mysql.user # # lists all the information in mysql users

DESC westos; # # View the data structure of westos table

FLUSH PRIVILEGES; # # refresh database information

SELECT Host,User,Password FROM user; filters Host,User,Password information from the user table

(2) user permission settings

Mysql-u root-p

Enter password:

SHOW DATABASES

+-+

| | Database |

+-+

| | information_schema |

| | mysql |

| | performance_schema |

+-+

3 rows in set (0.00 sec)

USE mysql

CREATE USER redhat@localhost identified by 'redhat'; # # create user redhat password redhat

GRANT INSERT on *. * to redhat@localhost; # # user redhat has local insert permission

GRANT CREATE on *. * to redhat@localhost; # # user redhat has local create permission

SHOW GRANTS FOR redhat@localhost # # all local permissions of the user redhat

FLUSH PRIVILEGES; # # refresh database information

REVOKE CREATE on *. * from redhat@localhost; # # remove the local creation permission of user redhat

REVOKE INSERT on *. * from redhat@localhost; # # remove the local insert permission of user redhat

DROP USER redhat@localhost; # # redhat for the initial user

(3) change the password (the original password is lost)

Systemctl stop mariadb.service # # close mariadb.service

Mysqld_safe-- skip-grant-tables & # # skip the grant-tables authorization table and log in to the local mysql database without authentication

Mysql-uroot # # No password is required when entering the database

SELECT * FROM mysql.user

UPDATE mysql.user set Password=passwd ('westos') WHERE User='root'; updates the mysql.user table if the password of the root user is encrypted westos

Ps aux | grep mysql # # View mysql process

Killall-9 mysqld_safe # # close the process

Ps aux | grep mysql

Avahi 480 0.0 0.0 30028 1476? Ss 20:06 0:00 avahi-daemon: running [mysql-server.local]

Mysql 2550 0.04.7 843940 90168 pts/0 Sl 20:54 0:00 / usr/libexec/mysqld-basedir=/usr-datadir=/var/lib/mysql-plugin-dir=/usr/lib64/mysql/plugin-user=mysql-skip-grant-tables-log-error=/var/log/mariadb/mariadb.log-pid-file=/var/run/mariadb/mariadb.pid-socket=/var/lib/mysql/mysql.sock

Root 2758 0.0 112640 940 pts/0 R + 21:04 0:00 grep-color=auto mysql

Kill-9 2550

Ps aux | grep mysql

Avahi 480 0.0 0.0 30028 1476? Ss 20:06 0:00 avahi-daemon:running [mysql-server.local]

Root 2760 0.0 112640 940 pts/0 R + 21:05 0:00 grep-color=auto mysql

Systemctl start mariadb # # enable the service

(4) change the password (the original password exists)

Mysqladmin-uroot-pwestos password redhat # # change the password westos to redhat

(5) the creation of database, the establishment of tables and the perfection of records.

CREATE DATABASE westos; # # create a database

SHOW DATABASES; # # list databases

+-+

| | Database |

+-+

| | information_schema |

| | mysql |

| | performance_schema |

| | westos |

+-+

4 rows in set (0.00 sec)

Use westos; # # enter westos database

Database changed

CREATE TABLE redhat (username varchar (10) not null, password varchar (20) not null, class varchar (10)); # # create table redhat header username (cannot be empty), password (cannot be empty), class

Query OK, 0 rows affected (0.02 sec)

DESC redhat # # display redhat table structure

->

+-+ +

| | Field | Type | Null | Key | Default | Extra | |

+-+ +

| | username | varchar (10) | NO | | NULL |

| | password | varchar (20) | NO | | NULL |

| | class | varchar (10) | YES | | NULL |

+-+ +

3 rows in set (0.00 sec)

INSERT INTO redhat VALUES ('lee','abc','01'); # # insert records into the table

INSERT INTO redhat VALUES ('wee','abc','02')

(6) data backup

Mysqldump-uroot-predhat mysql > / mnt/my.sql backup mysql library to / mnt/my.sql

Mysql-uroot-predhat westos < / mnt/my.sql restore / mnt/my.sql to the westos library

So much for the operation of mysql. You can continue to pay attention to what you want to know about other related issues.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report