Common MySQL commands in cmd

Navicat for MySQL is a powerful database management and development tool designed specifically for MySQL. The graphical interface makes it easier for you to operate.

  1. In addition, you can press ↑ to return to the last command, and you can correct it at this time.
    2. Exit MySQL: quit or exit

The following are commonly used MySQL commands:
show databases; display database
create database name; create database
use databasename; select database
drop database name to directly delete the database, without reminding
show tables; display table
describe tablename; display specific table structure
select with distinct removal Repeat the field
mysqladmin drop databasename before deleting the database, there is a prompt.
Display the current mysql version and current date
select version(), current_date;
modify the root password in
mysql : shell>mysql -h localhost -u root -p //log in to
mysql> update user set password=password("xueok654123") where user ='root';
mysql> flush privileges //Refresh the database
mysql>use dbname; Open the database:
mysql>show databases; show all databases
mysql>show tables; show all the tables in the database mysql: first use mysql; then
mysql>describe user; display the column information of the user table in the mysql database);
grant
Create user firstdb (password firstdb) and database, and grant permissions to firstdb database
mysql> create database firstdb;
mysql> grant all on firstdb.* to firstdb identified by'firstdb'
will automatically create user firstdb
mysql default is the local host is localhost , The corresponding IP address is 127.0.0.1, so you will make an error when logging in with your IP address. If you want to log in with your IP address, you must first authorize and use the grant command.
mysql>grant all on. to [email protected] identified by “123456”;
Note: There are various permissions between grant and on, for example: insert, select, update, etc.
After on is the database name and table name, the first one means For all databases, the second one means that all tables
root can be changed to your user name, @ can be followed by domain name or IP address, and the password for login after identified by can be omitted, that is, the default password or empty password .
drop database firstdb;
Create a complete super user who can connect to the server from anywhere, but you must use a password something to do this
mysql> grant all privileges on. to user@localhost identified by'something' with
adding new users
Format: grant select on database.* to username@login host identified by "password"
GRANT ALL PRIVILEGES ON. TO monty@localhost IDENTIFIED BY'something' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON. TO monty@"%" IDENTIFIED BY 'something' WITH GRANT OPTION;
delete authorization:
mysql> revoke all privileges on. from root@"%";
mysql> delete from user where user="root" and host="%";
mysql> flush privileges;
create a user custom logs in on a specific client it363.com and can access a specific database fangchandb
mysql >grant select, insert, update, delete, create,drop on fangchandb.* to custom@ it363.com identified by 'passwd'
Rename table:
mysql> alter table t1 rename t2;
mysqldump
backup database
shell> mysqldump -h host -u root -p dbname >dbname_backup.sql
restore database
shell> mysqladmin -h myhost -u root -p create dbname
shell> mysqldump -h host -u root -p dbname <dbname_backup.sql
If you only want to unload the table creation command, the command is as follows:
shell> mysqladmin -u root -p -d databasename> a.sql
If you only want to unload the sql command that inserts the data, and do not need to build the table command, the command is as follows:
shell> mysqladmin -u root -p -t databasename> a.sql
then if I only want What should I do when I don’t want any sql commands?
mysqldump -T./ phptest driver
Among them, the plain text file can be unloaded only when the -T parameter is specified, which means the directory where the data is unloaded, and ./ means the current directory , Which is the same directory as mysqldump. If you do not specify the driver table, the data of the entire database will be unloaded. Each table will generate two files, one is a .sql file, which contains the execution of table creation. The other is a .txt file, which only contains data and no sql command.
You can store the query in a file and tell mysql to read the query from the file instead of waiting for keyboard input. You can use the shell to type the redirection utility to accomplish this. For example, if there are
queries stored in the file my_file.sql , you can execute these queries as follows:
For example, if you want to write the table creation statement in sql.txt in advance,
mysql> mysql -h myhost -u root -p
Mysql5. 0 Character sets supported
The character set control in MySQL is more detailed and can be divided into database level, table level, and field level (this is different from ORACLE). The character set I changed last time was at the database level, and it had no effect on the table sysuser, so there was a situation where the character set was changed but the Chinese could not be inserted.
Drop TABLE IF EXISTS firstdb.users;
Create TABLE firstdb.users (
id int(11) NOT NULL auto_increment,
username varchar(40) default NULL,
birthday date default NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=gb2312;
When compiling MySQL, specify a default character set, this character set is latin1;
when installing MySQL, you can specify a default character set in the configuration file (my.ini), if not specified, this value is inherited from the time of compilation Specified;
when starting mysqld, you can specify a default character set in the command line parameters, if not specified, this value is inherited from the configuration file;
at this time character_set_server is set to the default character set;
when creating a For a new database, unless explicitly specified, the character set of this database is set to character_set_server by default;
when a database is selected, character_set_database is set to the default character set of this database;
When creating a table in this database, the default character set of the table is set to character_set_database, which is the default character set of this database;
when setting a column in the table, unless explicitly specified, the default character of this column The set is the default character set of the table;
this character set is the character set used by the actual data stored in the database, and the content of mysqldump is under this character set; Query Browser1.1 has poor support for Chinese input, so you can use the notebook to write it. After that, copy and execute
update firstdb.users set username='to' where id=3;
MYSQL Commonly used commands
1. Export the entire database
mysqldump -u username -p --default-character-set=latin1 database name> export the
file name (database default encoding is latin1)
mysqldump -u -p smgp_apps_wcnc WCNC> wcnc.sql
2. export a table
mysqldump -u username -p database name watches> export file name
mysqldump -u wcnc -p smgp_apps_wcnc users> wcnc_users.sql
3. Export a database structure
mysqldump -u wcnc -p -d -add-drop-table smgp_apps_wcnc >d:wcnc_db.sql
-d No data -add-drop-table Add a drop table before each create statement
4. Import the database
A: Commonly used source commands
enter the mysql database console,
such as mysql -u root -p
mysql>use database
and then use the source command, the following parameters are script files (such as .sql used here)
mysql>source wcnc_db.sql
B: use mysqldump command
mysqldump -u username -p dbname <filename

Guess you like

Origin blog.csdn.net/jiahuiandxuehui/article/details/109727943