【ubuntu 18.04】安装mysql5.7


1. 安装

sudo apt update
sudo apt install mysql-server mysql-client

2. 查看密码

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

3. 登录数据库修改用户密码

master@master:~$ mysql -u debian-sys-maint -p7ZEfzL5zOzDIsPve
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.36-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update mysql.user set authentication_string=password('123456') where user='root' and Host ='localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> update user set  plugin="mysql_native_password";
Query OK, 1 row affected (0.00 sec)
Rows matched: 4  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> quit;
Bye

4. 重新登录

master@master:~$ mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.36-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> exit
Bye

5. mysql8.0修改密码方法

use mysql;
alter user 'root'@'localhost' identified with mysql_native_password by '********';
flush privileges;

6. 进程管理

启动mysql:
方式一:sudo /etc/init.d/mysql start
方式二:sudo service mysql start
方式三:sudo systemctl start mysql.service
停止mysql: 方式一:
sudo /etc/init.d/mysql stop 方式二:sudo service mysql stop
方式三:sudo systemctl stop mysql.service 重启mysql: 方式一:
sudo/etc/init.d/mysql restart 方式二:sudo service mysql restart
方式三:sudo systemctl restart mysql.service

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM