阿里云的便宜机器实在弱爆了，有一次编译个 PHP 都能宕机，因此，编译 MYSQL 的事情，我也不怎么想了，直接 apt-get 吧...
安装 mysql 那是相当的简单，基本上两个步骤就够了：安装&安全配置。
1. 安装 mysql
apt-get install mysql-server
2. 配置 mysql
~# mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1 Please set the password for root here. New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success.
2.4. 禁止 root 远程访问
Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y Success.
By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - Dropping test database... Success. - Removing privileges on test database... Success.
Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done!
2.7. 重置 root 密码
3. mysql 常用命令
# 连接 mysql mysql -u用户名 -p密码 数据库名 #显示数据库列表 mysql>show databases; #选择数据库 mysql>use 数据库名; #显示table列表 mysql>show tables; #显示 table 表结构 mysql>desc 表名; #备份本地数据库 mysqldump -u用户名 -p密码 数据库名 > 备份文件路径\备份文件名称 #本地恢复数据库 mysqldump -u用户名 -p密码 数据库名 < 备份文件路径\备份文件名称