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

 9. 下面可以配置,让mysql被其他机器访问,不需要的可以略过。首先修改配置文件

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

  将bind-address = 127.0.0.1这一行注释掉

10. 进入mysql,执行

grant all on *.* to root@'%' identified by '你的密码' with grant option;
flush privileges;
quit;

11. 重启mysql。然后便可以使用工具连接mysql了

sudo service mysql restart

 

posted @ 2020-09-30 11:58  到三国卖栗子  阅读(137)  评论(0编辑  收藏  举报