ubuntu安装mysql

1. 下载安装mysql

sudo apt-get install mysql-server

2. 启动mysql

service mysql start

3. 确认是否启动成功,mysql节点处于LISTEN状态表示启动成功:netstat -tap |grep mysql

page@page-virtual-machine:~$ netstat -tap |grep mysql
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 localhost:mysql 0.0.0.0:* LISTEN -

4. 此时直接用root登录会报错,也不知道密码是什么。如果可以登录的,可以跳过修改密码这几步:步骤5,6,7

5. 查看账号和密码,使用对应账号和密码登录:sudo cat /etc/mysql/debian.cnf

page@page-virtual-machine:~$ sudo cat /etc/mysql/debian.cnf
[sudo] password for page:
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = dpAqezn4wnp7TdXV
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = dpAqezn4wnp7TdXV
socket = /var/run/mysqld/mysqld.sock

6. 使用配置文件中的账号密码登录

mysql -u debian-sys-maint -p

7. 在mysql中执行

use mysql;
update mysql.user set authentication_string=password('123456') where user='root' and Host ='localhost';
update user set  plugin="mysql_native_password";
flush privileges;
quit;

8. 此时可以使用root用户登录,密码即为刚修改的123456

mysql -u root -p

 

上一篇:Docker 引擎 - 支持的平台


下一篇:Debian live-build官方教程学习笔记