Tuesday, April 3, 2012

MySQL admin

mysql -u root -p                   -- Connect to Mysql

show databases;                     -- view databases
create database db_name;      -- create database db_name
create schema db_name;       -- create database db_name (schema <=> database)
use db_name;                        -- change database to db information_schema for all statements
show databases;                     -- list all databases
select database();                   -- show current database
help contents;                       -- access help path

create user test identified by 'test';                 -- create user
grant select on test.table_test to test;            -- grant select on table_test to user test
select user, host, password from mysql.user;  -- show all users
drop user test;                                               -- drop user
show grants;                                                  -- show user grants
show grants for 'user'@'host'                          -- show grants for a specific user

Tables are fully defined by using db_name.table_name.

desc table_name;                                           -- describe table
show tables;                                                   -- show database tables;
show index for table_name;                           -- show index for table_name
show table status;                                           -- list detailed table info
show create table table_name;                        -- list DDL for table_name create script
truncate table table_name;                             -- truncates table
analyze table test2;                                        -- analyze table
explain select * from table_tes where pk_col=1; -- view explain plan

select now();                                                  -- show system time
select @@tx_isolation;                                  -- show transaction isolation level  
show character set;                                        -- display a list of available character sets

set autocommit = 1;                                      -- default: set autocommit on

MySql administration (mysqladmin)


mysqladmin status
mysqladmin version



status -- Returns information on server state
password -- Changes a user password
shutdown -- Shuts down the MySQL server
reload -- Reloads the MySQL grant tables
refresh --  Resets all caches and logs
variables -- Returns values of all server variables
version -- Returns the server version
processlist -- Returns a list of all processes active on the server
kill -- Kills an active server process
ping -- Tests if the server is alive

Starting/stopping

/usr/local/mysql/support-files/mysql.server start
/usr/local/mysql/support-files/mysql.server stop
On Windows:
mysqladmin -u root -p shutdown

No comments:

Post a Comment