Mysql:useful Commands

Source: Internet
Author: User

Start/stop/restart MySQL:
===========================
On Linux start/stop/restart from the command line:
/etc/init.d/mysqld start
/etc/init.d/mysqld stop
/etc/init.d/mysqld restart

Some Linux flavours offer the service command too
Service mysqld Start
Service Mysqld Stop
Service mysqld Restart

Or
Service MySQL Start
Service MySQL Stop
Service MySQL Restart

On OS X to Start/stop/restart MySQL from the command line:
Sudo/usr/local/mysql/support-files/mysql.server start
Sudo/usr/local/mysql/support-files/mysql.server stop
Sudo/usr/local/mysql/support-files/mysql.server restart

Connect:
===========================
Mysql-h Localhost-u Myname-pmypassword

Set Password:
===========================
First Set:mysqladmin-u Root-password Root
Then
mysql> UPDATE mysql.user SET password=password (' New password ') WHERE user= ' root ';
mysql> FLUSH privileges;

Show Current User:
===========================
Mysql> Select User ();

Create Database:
===========================
Mysql> CREATE database OpenFire character set ' UTF8 ';

Show Databases:
===========================
mysql> show databases;

Use Database:
===========================
mysql> use database;

Show Tables:
===========================
Mysql> Show tables;

Empty Database with root user
===========================
mysql> DROP DATABASE Atomstore;
mysql> CREATE DATABASE Atomstore;

Grant Permission
===========================
GRANT all privileges on *. * to ' newuser ' @ ' localhost ';
FLUSH privileges;

Show table Structure
===========================
SHOW [Full] COLUMNS {from | in} tbl_name [{from | in} Db_name]
[like ' Pattern ' | WHERE Expr]

Drop Database
===========================
DROP DATABASE Atomstore;

Drop table
===========================
DROP TABLE xxxxx;

Create Table Samples
===========================
CREATE table if not exists ' fchat '. ' User ' (
' UserId ' int (7) NOT NULL auto_increment,
' username ' varchar (+) NOT NULL,
' Plainpassword ' varchar (+) NULL,
' Encryptedpassword ' varchar (255) NULL,
' Name ' varchar (+) NULL,
' Email ' varchar (+) NULL,
' CreationDate ' datetime NOT NULL,
' Modificationdate ' datetime NOT NULL,
Primary KEY (' UserId ')
);

CREATE table if not exists ' fchat '. ' Tag ' (
' TagId ' int (5) NOT NULL auto_increment,
' TagName ' varchar (+) NOT NULL,
' UserId ' int (7) is not NULL,
Primary KEY (' tagId '),
Foreign KEY (USERID)
References User (USERID)
ON DELETE Cascade
);

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.