【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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?