MySql命令行基本操作
生活随笔
收集整理的這篇文章主要介紹了
MySql命令行基本操作
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
啟動mysql服務: net start mysql關閉mysql服務: net stop mysql命令行登陸mysql:mysql -h localhost -u root -p admin 命令行登陸mysql:mysql -uroot -padmin 退出mysql控制臺:quit或者exit查看mysql控制臺當前信息:status顯示當前用戶名:select user();顯示當前日期:select current_date();顯示當前時間:select current_time();顯示當前時間戳(日期加時間):select current_timestamp();顯示所有的數據庫模式:show databases();MySql默認有三個數據庫模式:information_schema、mysql與test。切換到指定的數據庫模式:use 數據庫名稱。use kika;切換數據庫后,查看當前使用的那個數據庫模式:select database();登錄數據庫時,直接聲明數據庫模式的名稱:mysql -uroot -padmin kika列出某個數據庫模式中所有的數據表:show tables;查看某個表的表結構:desc 表名;或者describe 表名;例如:desc t_user;創建數據庫模式:create database 數據庫名稱;creata database testdatabase;或者creata database testdatabase CHARACTER SET utf8;刪除數據庫模式:drop database 數據庫名稱; drop database testdatabase;修改數據庫模式:alter database 數據庫名稱 CHARACTER SET utf8;alter database testdatabase CHARACTER SET utf8;創建表:create table if not exists tb_test( --如果表tb_test不存在則創建
id int primary key auto_increment,--定義主鍵,且自增
name varchar(200) not null, --字符類型列,最大長度200
salary float(11,2), --小數類型列,保留2位
birthday date, --日期類型列,只保存‘2013-02-08’這個種形式的
sleep time, --只保存時間‘08:12:52’
ts timestamp, --保存日期和時間:‘2013-11-17 18:25:44’
description text, --保存大文本,長度不限
picture blob --保存二進制數據
);創建臨時表(只在當前數據庫有效,斷開數據庫連接后,表自動刪除):create temporary table tb_temp(id integer,name varchar(50))刪除表: drop table 表名稱;修改表:1.刪除列:alter table table_name drop column_name; 列:alter table tb_test drop name;2.添加列:alter table table_name add column_name;列如:alter table tb_test add name varchar(200) not null;3.修改列的格式:alter table table_name change column_name new_name ;列如:alter table tb_test change name c_name integer;插入數據:insert into 表名(name,birthday,sex)values(‘張三’,‘1990-05-09’,‘男’);刪除數據:delete from 表名 where id=‘001’修改數據:update 表名 set sex=‘女’where id=‘002’執行mysql腳本文件(init.sql):mysql> \.init.sql 或者 source c:\init.sql
?
轉載于:https://www.cnblogs.com/ss-d/p/3428165.html
總結
以上是生活随笔為你收集整理的MySql命令行基本操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一步一步学Silverlight 2系列
- 下一篇: cocos2d-x for androi