linux 安装mysql及配置

ubuntu 18.04

1.安装

apt-get install -y mysql-server

使用上述命令即可完成mysql的安装,有些教程建议install mysql-client,实践表明,上述命令同时完成client的安装。

安装以后,mysql是在后台运行的,可以通过service命令查看mysql的运行情况:

service mysql status
或者
systemctl status mysql

2.修改root的默认密码

mysql的配置文件放在/etc/mysql目录下,具体为:

# 查看文件目录
root@ubuntu:/etc/mysql# ls
conf.d  debian.cnf  debian-start  my.cnf  my.cnf.fallback  mysql.cnf  mysql.conf.d


# 查看debian.cnf,借此登录mysql
root@ubuntu:/etc/mysql# cat debian.cnf 
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = V5kqkke6kuSbaKcj
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = V5kqkke6kuSbaKcj
socket   = /var/run/mysqld/mysqld.sock

# 根据cnf文件信息登录mysql
mysql -u debian-sys-maint -p
# 输入刚刚的password

# 进入mysql client,变更root密码
show databases;
use mysql;
update user set authentication_string=PASSWORD("root") where user='root'; # root用户密码也是root
update user set plugin="mysql_native_password";
flush privileges;
exit;

原文地址:https://www.cnblogs.com/davis12/p/14577246.html