In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Mysql Common commands (required)
1) Export test_db database
Command: mysqldump-u user name-p database name > exported file name
Mysqldump-u root-p test_db > test_db.sql
1.1) Export all databases
Mysqldump-u root-p-all-databases > mysql_all.sql
2) Export a table
Command: mysqldump-u user name-p database name table name > exported file name
Mysqldump-u root-p test_db test1 > test_test1.sql
3) Export a database structure
Mysqldump-u root-p-d-add-drop-table test_db > test.sql
-d No data-add-drop-table adds a drop table before each create statement
4) Import database
① common source commands
Go to the mysql database console
Such as mysql-u root-p
Then use the source command, followed by a script file (such as .sql used here)
Mysql > source wcnc_db.sql
② uses the mysqldump command
Mysqldump-u username-p dbname
< filename.sql ③使用mysql命令 mysql -u username -p -D dbname < filename.sql 5)mysql进入与退出 进入: mysql -uroot -p //进入mysql控制台 mysql -uroot -p password //进入mysql控制台 mysql -p //进入mysql控制台 退出: quit或exit 6)数据库操作 1、创建数据库 命令:create database 例如:建立一个名为test_db的数据库 mysql>Create database test_db
2. Show all databases
Command: show databases (Note: there is an s at the end)
Mysql > show databases
3. Delete the database
Command: drop database
For example: delete the database named test_db
Mysql > drop database test_db
4. Connect to the database
Command: use
For example: access to test_db database
Mysql > use test_db
Screen Tip: Database changed
5. View the database currently in use
Mysql > select database ()
6. Table information contained in the current database
Mysql > show tables; (Note: there is an s at the end)
7. View the database character set
Mysql > show variables like'% char%'
7) Table operation, which should connect to a database before operation
1. Create a table
Command: create table ([,.. ])
For example: create a table called test01, and create two fields, id, name, and data length (using characters to define length units)
Mysql > create table test01 (id varchar (20), name varchar (20))
2. View the table structure
Command: desc table name, or show columns from table name
For example: view test table structure
Mysql > desc test
Mysql > show columns from test
Mysql > describe test
Mysql > show create table test
3. Delete the table
Command: drop table
For example: delete a table named test_db
Mysql > drop table test_db
4. Insert data
Command: insert into [[,.. ])] Values (value 1) [, (value n)]
For example, insert two records into the table test, which indicate that the number is 001 and the name is yangxz
Mysql > insert into test values ("001", "yangxz")
5. Query the data in the table
1) query all rows
Command: select from
< 表名 >Where
< 表达式 >For example: view all the contents (data) in the table test
Mysql > select * from test
For example: find the id=001 content in the test table
Mysql > select * from test where id=001
For example: find the content in the test table that already starts with id 0
Mysql > select * from test where id like "0%"
2) query the first few rows of data
For example: view the first two rows of data in table test
Mysql > select * from test order by id limit 0Pol 2
Or:
Mysql > select * from test limit 0Pol 2
6. Delete the data in the table
Command: delete from table name where expression
For example: delete the record numbered 001 in table test
Mysql > delete from test where id=001
7. Modify the data in the table
Command: update table name set field = new value, … Where condition
For example: modify the contents of the name field in test table
Mysql > update test set name='admin' where id=002
For example: modify the length of the name field in the test table
Mysql > alter table test modify column name varchar (30)
8. Add fields to the table
Command: alter table table name add field type other
For example, a field passtest is added to the table test, the type is int (4), and the default value is 0
Mysql > alter table test add passtest int (4) default'0'
9. Change the table name:
Command: rename table original table name to new table name
For example: change the name of test to test1 in the table
Mysql > rename table test to test1
8) change the password
Mysqladmin-uroot-p Old password password New password
Mysql > use mysql
Mysql > update mysql.user set password=' New password 'where user=' username'
Flush privileges
Mysql > set password for user name @ localhost=password ('your password')
Flush privileges
9) increase number of users
For example: add a test user with a password of 1234
Mysql > insert into mysql.user (Host,User,Password) values ("localhost", "test", password ("1234"))
Flush privileges
10) Delete the user
For example: delete test user
Mysql > delete from user where user='test' and host='localhost'
Flush privileges
11) Database authorization
Command: grant permission on database name. * to user name @ localhost identified by 'password'
For example: authorized test users have all permissions of the test_ DB library
Grant all on test_db.* to test@localhost identified by '123456'
For example: authorized test user to have select,update permission of test_ DB library
Grant select,update on test_db.* to test@localhost
12) Lock table
Mysql > flush tables with read lock
Unlock:
Mysql > unlock tables
13) View current user
Mysql > select user ()
14) MYSQL password cracking method
Stop the Mysql service and start it by skipping permissions, with the following command:
Service mysqld stop
/ usr/local/mysql/bin/mysqld_safe-user=mysql-skip-grant-tables &
Enter mysql at the shell terminal and press enter to enter the mysql command line
Since MYSQL users and password authentication information are stored in the user table in the mysql database, you need to enter the mysql library.
Mysql > use mysql
Mysql > update user set password=password ('123456') where user='root'
Mysql > flush privileges
After the MYSQL root password has been modified, you need to stop the startup process of skipping the permission table with Mysql, start MYSQL in a normal way, and log in with a new password to enter the Mysql database.
15) View the storage engine provided by Mysql
Mysql > show engines
View the mysql default storage engine
Mysql > show variables like'% storage_engine%'
View mysql system version
Mysql > select version ()
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.