Ubuntu部署MySQL数据库

xiaoxiao2025-04-16  10

1 安装

# 服务端,运行mysql服务,代码实现数据存取 sudo apt-get install mysql-server # 客户端,访问mysql数据库,终端用户访问 suso apt-get install mysql-client

2 mysql状态

2.1 版本

mysql -V mysql Ver 14.14 Distrib 5.7.27, for Linux (x86_64) using EditLine wrapper

2.2 运行状态

cmd1 sudo netstat -tap | grep mysql # 正在运行 tcp 0 0 localhost:mysql 0.0.0.0:* LISTEN 8715/mysqld cmd2 systemctl status mysql.service ● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en Active: active (running) since 一 2019-08-19 11:27:45 CST; 2 days ago Main PID: 1418 (mysqld) CGroup: /system.slice/mysql.service └─1418 /u2s/master/MySQL/sbin/mysqld --daemonize --pid-file=/var/run

3 登录及修改密码

3.1 寻找初始密码

#进入配置目录目录 cd /etc/mysql sudo vim debain.cnf # Automatically generated for Debian scripts. DO NOT TOUCH! [client] host = localhost user = debian-sys-maint password = XCZ1Fmla904Eqopn socket = /var/run/mysqld/mysqld.sock [mysql_upgrade] host = localhost user = debian-sys-maint password = XCZ1Fmla904Eqopn socket = /var/run/mysqld/mysqld.sock

3.2 登录

#格式 mysql -u debian-sys-maint -p Enter password:XCZ1Fmla904Eqopn #结果 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.24-0ubuntu0.18.04.1 (Ubuntu) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)

3.3 修改密码

#进入数据库,显示数据库 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) #修改mysql密码 mysql>use mysql; #修改root用户密码 mysql>update set authentication_string=PASSWORD("新密码") where use='root'; #更新本地密码 mysql>update user set plugin="mysql_native_password"; #授权 mysql>flush privileges; mysql>quit; #重启mysql sudo /etc/init.d/mysql restart

4 重新登录

mysql -u root -p Enter password:*****

5 mysql状态控制

5.1 启动

sudo /etc/init.d/mysql start [ ok ] Starting mysql (via systemctl): mysql.service.

5.2 重启

#重启mysql服务 sudo /etc/init.d/mysql restart [ ok ] Restarting mysql (via systemctl): mysql.service.

5.3 停止

sudo /etc/init.d/mysql stop [ ok ] Stopping mysql (via systemctl): mysql.service.

6 注意

6.1 查不到mysql版本

cmd mysql -V Result The program 'mysql' can be found in the following packages: * mysql-client-core-5.7 * mariadb-client-core-10.0 Try: sudo apt install <selected package> Reason&Plan 没有安装客户端,安装客户端即可. sudo apt-get install mysql-client-core-5.7

6.2 不能登录mysql

cmd mysql -u root -p Result The program 'mysql' can be found in the following packages: * mysql-client-core-5.7 * mariadb-client-core-10.0 Try: sudo apt install <selected package> Reason&Plan 没有安装客户端,安装客户端即可. sudo apt-get install mysql-client-core-5.7

参考文献 [1]https://zhidao.baidu.com/question/877079040418639572.html [2]https://www.cnblogs.com/super-zhangkun/p/9435974.html [3]https://blog.csdn.net/qq_32846595/article/details/70214271 [4]https://www.jianshu.com/p/22bce531be10 [5]https://blog.csdn.net/Nancy50/article/details/81080693


转载请注明原文地址: https://www.6miu.com/read-5028367.html

最新回复(0)