Common operation commands for MySQL in Linux system
Service:
# chkconfig --list list all system services
# chkconfig --list | grep on List all started system services# chkconfig --list mysqld
# whereis mysql View the file installation path
# which mysql Query the path of the running file (folder address)
usr/bin/mysql refers to: the running path of mysql
var/lib/mysql refers to: the storage path of the mysql database file
usr/lib/mysql refers to: the installation path of mysql
Add environment variables:
# vi/etc/profile
# export MYSQL_HOME=/usr/local/mysql
# export PATH=$PATH:$MYSQL_HOME/bin
1.Database instructions:
# service mysqld start Start MySQL
# service mysqld restart Restart MySQL
# service mysqld stop Stop MySQL
2.Enter MySQL form operation
# -u root -p /mysql -h localhost -u root -p DatabaseName; enter MySQL
MySQL> show databases; list databases
MySQL> create database XXX; create database XXXMySQL> use databaseName; use database databaseName
MySQL> show tables; list formsMySQL> create table mytablename (ID int auto_increment not null primary key,usename varchar(20),password varchar(64),sex varchar(10),address varchar(20)); create form
MySQL> drop table mytablename ; delete form
MySQL> drop database databasename; delete database
3.Add, delete, modify, and check
MySQL> insert into mytablename values('','zhangsan','123456','fomale','guiyanag'); insert
MySQL> select * from mytablename ; find verification results
MySQL> select * from mytablename where ID = '1'; precise searchMySQL> update mytablename set address ='shanghai' where username ='zhangsan'; modify zhangsan's address to shanghai
MySQL> delete from mytablename where ID = '1'; delete record
New universal user
grant select On database.* to username@localhost identity by'password'
The username user_1 and the password is 123456
The user can log in to the database from any PC
MySQL> grant select,insert update,delete on *.* to user_1@"%" identity by "123456";
Create a user who can only operate the database on this machine
The username user_2 and the password is 123456
MySQL> grant select,insert update,delete on *.* to user_2@localhost identity by "123456";
Log in to the database
MySQL> -u user_1 -p -h IP address;
In addition, I will list some commonly used commands for reference only:
Other mysql database related operations are as follows
(1) Create database TestDB mysql> create database TestDB;
(2) Make TestDB database the current default database mysql> use TestDB;
(3) Create table customers mysql in TestDB database> create table customers(userid int not null, username varchar(20) not null);
(4) Show database list mysql> show databases;
(5) Show the tables in the database mysql> show tables;
(6)Delete table customers mysql> drop table customers;
(7) Display the structure of the customers table mysql> desc customers;
(8) Insert a record into the customers table mysql> insert into customers(userid, username) values(1,'hujiahui');
(9) Let the operation take effect in time; mysql> commit;
(10) Query records in customers mysql> select * from customers;
(11) Update the data in the table mysql> update customers set username='DennisHu' where userid=1;
(12) Delete records in the table mysql> delete from customers;
(13) Grant likui users permission to access the database # grant select, insert, update, delete on *.* to likui@localhost indentified by "123456";
0 Comments