MySQL


简易指南

show databases;
create database dbname;
drop database dbname;

use dbname;
show tables;
select * from tbname;

-- convert mydb character to utf8
use mydb;
alter databases mydb character set utf8;
alter table tablename convert to character set utf8 collate utf8_bin;

-- add a new user and authorize the right privileges
CREATE DATABASE db;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER
ON db.* TO 'user'@'localhost' IDENTIFIED BY 'mpsRbIN8yysVDaZL';
-- add user `dump` for backup
GRANT SELECT, LOCK TABLES ON db.* TO 'dump'@'localhost' IDENTIFIED BY 'trjLHAR1xPleUAQr';
-- apply
FLUSH PRIVILEGES;

-- export the select result to a file which should be writable by mysql command
use dbname
select * from user where create_time like '2010-12-01%' limit 100 into outfile '/tmp/file';

重置密码

service mysqld stop
mysqld --skip-grant-tables
mysql -u root -p -e "UPDATE mysql.user SET password=PASSWORD('rootpasswd') WHERE user='root';"
mysqladmin -u root -p shutdown
service mysql start

# Initial
service mysqld stop
mysql_install_db
service mysql start
mysqladmin -u root password "rootpasswd"