User Tools

Site Tools


mysql

Login

$ mysql -u root -p

List Users

mysql> SELECT USER FROM mysql.user;

Databases

List Databases

mysql> SHOW DATABASES;

Change/Select Database

mysql> USE <database>;

Tables

List Tables

mysql> SHOW TABLES;

List Table Columns

mysql> SHOW COLUMNS FROM <table>;

VARCHAR

The max length of varchar in MySQL is 64KB

VARCHAR(65535)

Lower with a multi-byte character set

VARCHAR(21844) CHARACTER SET utf8

Execute SQL File

mysql> SOURCE '/<path>/<to>/<file>.sql';

Indexes

Add Index

mysql> ALTER TABLE <table> ADD INDEX <index> (<column>);

Show Indexes

mysql> SHOW INDEX FROM <table>;

Drop Index

mysql> ALTER TABLE <table> DROP INDEX <index>;

Insert

Insert or Update

mysql> INSERT INTO <table> (field1, field2, field3) VALUES ('value1', 'value2','value3') ON DUPLICATE KEY UPDATE field1='value1', field2='value2', field3='value3';
mysql.txt · Last modified: 2016/05/14 11:04 (external edit)