Ubuntu部署MySQL数据库

版权声明:转载请注明出处。 https://blog.csdn.net/Xin_101/article/details/83504429

Ubuntu部署

1.1 安装

sudo apt-get install mysql-server
suso apt-get install mysql-client

1.2 mysql状态

  • 运行状态
sudo netstat -tap | grep mysql
# 正在运行
tcp   0  0 localhost:mysql   0.0.0.0:*       LISTEN      8715/mysqld  

1.3 登录及修改密码

  • 寻找初始密码
#进入配置目录目录
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
  • 登录
#格式
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)

  • 修改密码
#进入数据库,显示数据库
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

1.4 重新登录

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

1.5 mysql状态控制

  • 启动
sudo /etc/init.d/mysql start
[ ok ] Starting mysql (via systemctl): mysql.service.
  • 重启
#重启mysql服务
sudo /etc/init.d/mysql restart
[ ok ] Restarting mysql (via systemctl): mysql.service.
  • 停止
sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.

[参考文献]
[1]https://zhidao.baidu.com/question/877079040418639572.html
[2]https://www.cnblogs.com/super-zhangkun/p/9435974.html


猜你喜欢

转载自blog.csdn.net/Xin_101/article/details/83504429