Simple operation for MySQL

Source: Internet
Author: User

# #mysql简单操作 # # #
#在mysql中一般用 ";" Do the end.
(1) Yum install mariadb-server-y # #安装软件
Systemctl Start MARIADB # #开启服务
Mysql_secure_installation # #第一次安装mysql, because there is no password when you first enter MySQL, you can use this > command to operate MySQL, add password.
Mysql-u root-predhat # #以超级用户身份进入mysql, password Redhat
SHOW DATABASES; # #显示数据库
SHOW TABLES; # #显示表
use MySQL; # #进入mysql数据库
Setect * from Mysql.user # #列出mysql用户中的所有信息
DESC Westos; # #查看westos表的数据结构
FLUSH privileges; # #刷新数据库信息
SELECT Host,user,password from User; Filtering Host,user,password information from the User table
(2) User rights 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 [email protected] identified by ' Redhat '; # #创建用户redhat Password Redhat
GRANT INSERT On * * to [email protected]; # #用户redhat在本地有插入权限
GRANT CREATE On * * to [email protected]; # #用户redhat在本地有创建权限
SHOW GRANTS for [email protected] # #用户redhat在本地的所有权限
FLUSH privileges; # # Refresh Database Information
REVOKE CREATE on * * FROM [email protected]; # #移除用户redhat在本地的创建权限
REVOKE INSERT on * * FROM [email protected]; # #移除用户redhat在本地的插入权限
DROP USER [email protected]; # #移初用户redhat
(3) Change password (original password is lost)
Systemctl Stop Mariadb.service # #关闭mariadb. Service
Mysqld_safe--skip-grant-tables & # #跳过grant-tables authorization table does not require authentication login to the local MySQL database
Mysql-uroot # #进入数据库时不需要密码
SELECT * from Mysql.user;
UPDATE Mysql.user Set password=passwd (' Westos ') WHERE user= ' root '; Update Mysql.user The password for the root user in the table is encrypted Westos
PS aux | grep MySQL # #查看mysql进程
Killall-9 Mysqld_safe # #关闭进程
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.0 4.7 843940 90168 pts/0 Sl 20:54 0:00/usr/libexec/mysqld--basedir=/usr--datadir=/var/lib/mys QL--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 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 0.0 112640 940 pts/0 r+ 21:05 0:00 grep--color=auto MySQL
Systemctl Start MARIADB # #开启服务
(4) Change password (original password exists)
Mysqladmin-uroot-pwestos Password Redhat # #将密码westos改为redhat

(5) Creation of database and establishment of tables and improvement of records
CREATE DATABASE Westos; # #创建数据库
SHOW DATABASES; # #列出数据库
+--------------------+
| Database |
+--------------------+
| Information_schema |
| MySQL |
| Performance_schema |
| Westos |
+--------------------+
4 rows in Set (0.00 sec)
Use Westos; # #进入westos数据库
Database changed
CREATE TABLE Redhat (username varchar () not NULL, password varchar (a) not NULL, class varchar (10)); # #创建表redhat Table header username (cannot be empty), password (cannot be empty), class
Query OK, 0 rows affected (0.02 sec)

DESC Redhat # #显示redhat表结构
;
+----------+-------------+------+-----+---------+-------+
| 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 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 Westos Library




Simple operation for MySQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.