Common operation commands for MySQL in Linux systems

Source: Internet
Author: User
Tags mysql in mysql query mysql view

Service:

# chkconfig--list List all system services
# chkconfig--list | grep on lists all started system services

# chkconfig--list mysqld

# whereis MySQL View file installation path
# which MySQL query run file path (folder address)
Usr/bin/mysql refers to: The running path of MySQL
Var/lib/mysql refers to: The storage path of MySQL database files
Usr/lib/mysql refers to: MySQL installation path

To add an environment variable:

# Vi/etc/profile
# Export Mysql_home=/usr/local/mysql
# Export path= $PATH: $MYSQL _home/bin

1. Database directives:

# service mysqld start MySQL
# service mysqld Restart restart MySQL
# service mysqld stop stops MySQL

2. Enter MySQL form operation

#-U root-p /mysql-h localhost-u root-p databasename;    into MySQL
 mysql& Gt Show databases;            list Database
 MySQL>  Create DATABASE xxx;      databases XXX

 MySQL>  use databasename;          working with databases DatabaseName
 MySQL>  show tables;               list Forms

Mysql> create TABLE Mytablename ( ID int auto_increment NOT NULL primary key,usename varchar, password varchar (+), sex varchar (20), address varchar ;  creating a form
mysql> drop table Mytablename;                  Delete form
mysql> drop database databasename;               Delete Database

3. Adding and deleting changes

mysql> INSERT into mytablename values (' ', ' Zhangsan ', ' 123456 ', ' fomale ', ' guiyanag '); Insert

Mysql> select * from Mytablename; Find Validation Results
Mysql> SELECT * from mytablename where ID = ' 1 '; Precise Search

Mysql> Update mytablename Set address = ' Shanghai ' where username = ' Zhangsan '; Modify the address of Zhangsan to Shanghai

Mysql> Delete from mytablename where ID = ' 1 '; Deleting records

New Universal User

  grant select On database.* to [email protected] identity by ‘password‘

User name user_1 password is 123456

The user can log on to the database operation from any PC

MySQL> grant select,insert update,delete on *.* to [email protected]"%" identity by "123456";

Create a user who can only operate the database on this computer

User name user_2 password is 123456

MySQL> grant select,insert update,delete on *.* to [email protected] identity by "123456";

Log in to the database library

MySQL> -u user_1 -p -h IP地址;

In addition, I enclose some common commands for reference only:

Other MySQL database related operations are as follows

(1) Create DATABASE TestDB mysql> create databases TestDB;
(2) Make TestDB database mysql> use TestDB for the current default database;
(3) CREATE table in TestDB database customers mysql> CREATE TABLE customers (userid int NOT NULL, username varchar () is not null);
(4) Display database list mysql> show databases;
(5) Display the table in the database mysql> show tables;
(6) Delete Table Customers mysql> drop table customers;
(7) Showing 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) Querying the 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 the records in the table mysql> Delete from customers;
(13) Grant Likui user permission to access the database # Grant SELECT, INSERT, UPDATE, delete on *. * to [email protected] indentified by "123456";

Common operation commands for MySQL in Linux systems

Related Article

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.