Mysql8.xx安装与配置
安装和开启服务
sudo apt install mysql-server
sudo apt install mysql-client
# 开启mysql服务
sudo service mysql start
登录和修改密码
# 输入以下指令
$ sudo cat /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = YyRq13G5ldqbXp6h
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = YyRq13G5ldqbXp6h
socket = /var/run/mysqld/mysqld.sock
在输出的内容中找到用户名和密码,登录Mysql
$ mysql -udebian-sys-maint -pYyRq13G5ldqbXp6h
进入mysql后使用以下指令修改root用户的密码
flush privileges;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
flush privileges;
退出mysql,现在可以用root用登录了
mysql -uroot -p123456
远程登录设置
mysql root 账户默认只能在本机使用,需要进行以下配置开启远程登录
-- 添加一个用于远程登录的账户
create user 'luan'@'%' identified by '123456';
-- 赋予远程登录的权限
grant all privileges on *.* to 'luan'@'%';
flush privileges;
退出mysql,修改配置文件
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address = 127.0.0.1 修改为(注释掉)
#bind-address = 127.0.0.1
并重启
sudo service mysql restart
一切OK的话,就可以在其它主机链接数据库了。