ubuntu16上安装mysql并配置

1. 安装

apt-get install mysql-server即可

版本是5.7.30

2. 运行

service mysql start

(需要注意,一定要有/etc/mysql目录的存在,不然可能只看到出错,但没有日志)

3. 登录

初始密码是在/etc/mysql/debian.cnf中

mysql -u debian-sys-maint -p

mysql> use mysql;

mysql> update mysql.user set authentication_string=password(‘123456‘) where user=‘root‘ and Host=‘localhost‘;

mysql> update user set plugin="mysql_native_password";

mysql> flush privileges;

mysql> quit;

# service mysql restart

mysql -uroot -p   用新设置的密码登录

4. 配置远程访问

mysql> create database qcqc;

mysql> GRANT ALL PRIVILEGES ON qqqc.* TO IDENTIFIED BY "123456";

mysql> GRANT ALL PRIVILEGES ON qqqc.* TO "%" IDENTIFIED BY "654321";

mysql> flush privileges;

5. 配置一个utf8数据库

CREATE DATABASE IF NOT EXISTS yourdbname DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

相关推荐