# 服务端,运行mysql服务,代码实现数据存取
sudo apt-get install mysql-server
# 客户端,访问mysql数据库,终端用户访问
suso apt-get install mysql-client
mysql -V
mysql Ver 14.14 Distrib 5.7.27, for Linux (x86_64) using EditLine wrapper
sudo netstat -tap | grep mysql
# 正在运行
tcp 0 0 localhost:mysql 0.0.0.0:* LISTEN 8715/mysqld
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
#进入配置目录目录
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
mysql -u root -p
Enter password:*****
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.
mysql -V
The program 'mysql' can be found in the following packages:
* mysql-client-core-5.7
* mariadb-client-core-10.0
Try: sudo apt install
sudo apt-get install mysql-client-core-5.7
mysql -u root -p
The program 'mysql' can be found in the following packages:
* mysql-client-core-5.7
* mariadb-client-core-10.0
Try: sudo apt install
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