mysql -u username -p
- show databases on a server:
- show status of a database server:
- get user account info for a database server:
- show tables in a database:
- get information about a table in a database:
- get all contents of a table in a database:
- get the number of rows of a table in a database:
- create an account on database with a given password:
- Change user's password
SET PASSWORD FOR foo=PASSWORD('rubberchicken');
- Flush / reload grant tables (after changing table permissions):
- Conditionally drop a table, if it exists:
- Create a database:
- Copy a table from one database to another:
INSERT new_table_name SELECT * FROM old_database_name.table_name;
- Rename a table name:
- Eliminate duplicate results from a SELECT:
- Use Regular Expressions in a SELECT:
- Drop a column from a table:
- Check consistency of MyISAM database tables (must be in data dir), first flush the tables, then make sure nobody is accessing the tables, then run the command below (see http://www.lampspot.net/linux/how-to-guide-database-table-corruption-recognise-repair-and-prevent-by-jeng/):
- Flush database tables:
- Check database table status:
- Switch MyISAM tables to InnoDB tables (or switch to MyISAM if you have problems with InnoDB). (You must of course start mysqld with InnoDB support, which can be done by adding innodb options from the distributed my-medium.cnf file to your my.cnf file. This can be done with your table as long as you are not using two part autoincrement or FULLTEXT indexes.):
ALTER TABLE problem_table TYPE=INNODB
Get mysql version:mysql -V
Dump all contents of a database to a .sql file; will prompt for password:
mysqldump -u username -p database_name > /tmp/backup.sql
Restore all contents of a database from a .sql file (user must have access to do so; database must exist but be empty, I think; if tables already exist, this will not overwrite them):
mysql -u username -p database_name < /tmp/backup.sql
Change your mysql password (hostname matters?), will prompt for old password:
mysqladm -u username -p password newpassword
No comments:
Post a Comment