MySQL常用技巧

來源:互聯網
上載者:User

標籤:

1.查看MySQL版本資訊:

  1,登上 mysql>status;

  2,登上 mysql>select version();

  3,登上 mysql> select @@version;

  4,不登 [[email protected] ~]# mysql -V

  5,不登 [[email protected] ~]# mysql --help | grep Distrib ;

2.MySQL服務啟動:

  1,window下啟動服務 net start mysql

  2,window下停止服務 net stop mysql

  3,linux下啟動服務 service mysql start

  4,linux下停止服務 service mysql stop

3.當系統上啟動多個連接埠的MySQL的時候:

  1,串連的方式:mysql -uroot [email protected] -P 3306-S /mysqldata/database/data3306/mysql1.sock

  2,當出現連結不上的問題執行下面的命令:

    a)mysql>grant all privileges on *.* to [email protected]"%" identified by "password" with grant option;

    b)mysql>flush privileges;

4.MySQL的一些常用的查看命令:

  1,查看資料庫 mysql>show databases;

  2,選擇資料庫 mysql>use databasesname;

  3,查看資料庫中存在的函數 mysql> show function status;

  4,查看視圖 mysql>select * from information_schema.VIEWS;

  5,查看錶 mysql>show tables;

  6,查看觸發器 mysql>show triggers;

  7,查看目前使用者 mysql> select user();

  8,查看所有使用者 mysql>select  user,host,password from mysql.user;

  9,查看MySQL字元集 mysql>show variables like ‘%char%‘;

  10,查看資料庫的字元集 mysql>show create database databasename;

  11,查看錶的字元集 mysql>show create table databasename.tablename \G;

  12,查看當前選擇的資料 mysql>select database();

5.MySQL對錶和資料的一些操作命令:

  1, 將文字檔的資料裝載到表中:mysql>Load data local infile "mytable.txt" into table mytable;

  2,給欄位增加 primary key : mysql> alter table tablename add primary key(id);

  3,刪除primary key:   mysql>alter table tablename drop primary key; 或者 mysql>drop primary key on tablename;

  4,添加新欄位 :mysql>alter table tablename add column columnname char(1);或者 mysql>alter table tablename add field int(11) nosiged not null; 

  5,刪除欄位: mysql>alter table tablename drop column c;

  6,在列d上增加一個索引,並且使列a為主鍵: mysql>alter table tablename index(d),add primary key(a);

  7,增加一個新的AUTO_INCREMENT整數列,命名為c : mysql>alter table tablename add c int unsigned not null auto_increment  ,add index(c);

6.MySQL操作出現問題的解決辦法:

  1,出現function不能建立:

    mysql>show variables like ‘log_bin_trust_function_creators‘;

    mysql>set global log_bin_trust_function_creators=1;

MySQL常用技巧

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.