Author | Jeskson
Source | Dada front-end bistro
MySQL management, database management and data table management, user management.
Initialize the database, creating a database, check the database, delete the database.
Create a data table to view the data table, modify data table, delete data table.
User management, creating and deleting users, granting user rights and recovery, user settings and change the password.
Database Management
Initialize the database
mysqld --initialize
Start the database:
Start using windows server management interface; or to start using the MySQL command.
mysql -u root -p
Create a database
CREATE DATABASE
Statement to create a new database
CREATE DATABASE [db_name];
// 创建一个名为dada的数据库
create database data;
After the database is created, it will data
automatically generate a directory named data
directory, under the directory where the data will be stored in this database MySQL
is a database management system that supports running multiple databases.
View database
SHOW DATABASES
show databases;
Delete Database
DROP DATABASE db_name;
drop database dada; // 删除dada数据库
Delete database is an irreversible operation.
MySQL data management table
MySQL
Each database is equivalent to a container placed inside many many tables, the table contains a row for each particular data relationship information, a data record. In the data
directory, each corresponding to a directory database.
Table 3 correspond to each data file, respectively, ".frm", "myd", ". Myi" type of file.
Create a data table:
USE 数据库名;
CREATE TABLE 表名(字段名 类型(长度),字段名 类型(长度));
View Data Sheet
SHOW语句和DESCRIBE语句
// 查看数据库中有哪些表
SHOW TABLES;
// 此命令可以列出所有表名
show tables;
// DESCRIBE
DESCRIBE 库名.表名;
使用DESCRIBE语句可以查看某一个表的具体结构,并查看组成表的各字段的信息
use mysql;
describe user;
Use statement see the table describe each field name, type, length, if non-empty, if there is a primary key, default values, and notes and other information.
Modify Data Sheet
Modify data using the ALTER TABLE statement to implement, ALTER, modify a table, the table comprising a modified name, the field names, field types, etc. table structure.
Modify the table name
ALTER TABLE 旧表名 RENAME 新表名;
ALTER TABLE student RENAME student1;
Modify field names:
ALTER TABLE 表名 CHANGE 旧属性名 新属性名 新数据类型;
ALTER TABLE student1 CHANGE name s_name varchar(50);
Modify the field type
ALTER TABLE 表名 MODIFY 属性名 数据类型;
ALTER TABLE student1 MODIFY name varchar(2);
Increase the field:
ALTER TABLE 表名 ADD 属性名 数据类型;
ALTER TABLE student1 ADD sex char(1)
Delete field:
ALTER TABLE 表名 DROP 属性名;
ALTER TABLE student1 DROP sex;
Delete Data Sheet
USE 数据库名;
DROP 表名;
Use DROP
statement may delete database tables
DROP TABLE 数据库名.表名;
USE test;
DROP TABLE student1;
DROP TABLE test.sudent1;
mysql
User Management
Create and delete user
Create a user
CREATE USER 'username'@'host' IDENTIFIED BY 'password';
username
User Name Table to create
host
representation can log on which host
CREATE USER 'test1'@'localhost' IDENTIFIED BY '123';
CREATE USER 'test2'@'192.123.2.2' IDENTIFIED BY '12';
CREATE USER 'test3'@'%' IDENTIFIED BY '';
// identified
User deletes
DROP USER 'username'@'host';
The same syntax and delete user to create a user syntax
DROP USER 'test1'@'localhost';
Delete the local host database users
User rights granted and recycling
Users can authorize:
GRANT privileges ON dbname.tablename To 'username'@'host';
privileges
It represents the operating authority to grant users
dbname
It represents the database name
tablename
It represents the data table name
username
And host
represent the user name and login host
GRANT SELECT, INSERT ON mysql.test TO 'test1'@'%';
It represents an authorized user test1
all login host all of the mysql
database test
table have select
and insert
privileges.
GRANT ALL ON *.* TO 'test2'@'localhost';
If you want to grant users the appropriate operating authority for all databases and tables, is available“*”表示,如“*.*”。
Recovery of user rights
REVOKE privileges ON databasenamme,tablename FROM 'username'@'host';
REVOKE SELECT ON *.* FROM 'test2'@'localhost';
Recycling user test2
SELECT permission on all tables in all libraries in the local host database
Setup and change the user password
SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');;
username
To set or change the password for the user name
host
The user's login host
newpassword
To set or change the password
SET PASSWORD FOR 'test1'@'localhost' = PASSWORD('123');
❤️ Do not forget to leave your footprints learning [+ collection point Like Comments +]
Author Info:
[Author]: Jeskson
[original] Public number: Dada front-end bistro.
[Welfare]: No public reply "Information" self-study materials sent to spree (into the group to share what you want to say Ha, I did not see)!
[Reserved] Description: reproduced please indicate the source, thank you! ~
Large front-end development, front-end development positioning technology stack blog, PHP background knowledge, web full stack technology fields, data structures and algorithms, and so easy to understand network theory is presented to the junior partner. Thank you support, courtesy of love! ! !
If this number of local contents do not get bits (for example: to copyright or other problems), please contact us for rectification can be timely and will be processed in the first time.
Please thumbs up! Because you agree / encouragement is the greatest power of my writing!
Welcome attention to Dada 's CSDN!
This is a quality, attitude blog