目录

MySQL 常用命令

安装

1
sudo apt-get install mysql-server mysql-client

查看端口

1
sudo netstat -tap | grep mysql

设置初始密码

1
sudo mysql_secure_installation

登录

1
mysql -u root -ppassword

常用SQL

1
2
3
4
5
6
7
8
-- 设置密码安全等级
set global validate_password_policy=0;
-- 创建库
Create DATABASE IF NOT EXISTS `todev_dev` default charset utf8 COLLATE utf8_general_ci;
-- 设置 todev_dev 访问密钥
-- create user `todev_dev` identified by '111111';
-- grant all privileges on `todev_dev`.* to `todev_dev`@`%` identified by '111111';
ALTER USER 'todev_dev'@'%' IDENTIFIED BY '111111';

常见问题

无法远程连接

1
2
3
4
5
6
## 打开配置文件
vi /etc/mysql/mysql.conf.d/mysqld.cnf
## 注释 bind-address
#bind-address = 127.0.0.1
## 重启
service mysql restart