MySQL:Useful Commands

來源:互聯網
上載者:User

標籤:os   io   art   for   re   c   

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(’新密碼’) 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(64) not null,
    `plainPassword` varchar(32) null,
    `encryptedPassword` varchar(255) null,
    `name` varchar(100) null,
    `email` varchar(100) 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(64) not null,
  `userId` int(7) not null,
  primary key(`tagId`),
  foreign key (userId)
  references user(userId)
    on delete cascade
);

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.