参考博客:https://blog.csdn.net/weixin_36429334/article/details/77188821
- 查看有没有安装mysql
linyk3@ThinkPad-S5:~$ sudo netstat -tap | grep mysql
tcp 0 0 localhost:mysql *:* LISTEN 2942/mysqld
- 登录mysql
mysql -u root -h localhost -p
按照提示输入密码
linyk3@ThinkPad-S5:~$ mysql -u root -h localhost -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.21-0ubuntu0.16.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>
如果不是默认端口,可以加上 -P 选项:
mysql -u root -h localhost -P 5555 -p
- 启动,停止,重启mysql:
sudo service mysql start
sudo service mysql stop
sudo service mysql restart
- 忘记密码,重置mysql密码:
4.1 打开这个文件 /etc/mysql/debian.cnf, 查看默认分配的密码
[client]
host = localhost
user = debian-sys-maint
password = x8IyGAplQ76XKh1s ## 记住这个密码
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = x8IyGAplQ76XKh1s
socket = /var/run/mysqld/mysqld.sock
4.2 输入命令默认密码登录myql:
linyk3@ThinkPad-S5:~$ mysql -udebian-sys-maint -p
Enter password:
4.3 进入mysql后修改用户密码
update mysql.user set authentication_string=password('123456') where user='root'
4.4 刷新权限列表
flush privileges;
4.5 用新密码重新登录mysql即可
- 查看数据库:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| blog |
| bocbus |
| face |
| mysql |
| performance_schema |
| springmvc |
| sys |
+--------------------+
8 rows in set (0.05 sec)
mysql>
6.新建数据库:
create database chatbot;
如果提示没有权限,类似:
ERROR 1142 (42000): INSERT command denied to user 'radius'@'localhost' for table 'radgroupreply'
可以先看看用户权限:
show grant for 'user'@'%'
- 使用(进入)数据库:
mysql> use chatbot
Database changed
- 新建表:
mysql> CREATE TABLE `massageinfo` (
-> `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id',
-> `msgId` varchar(255) DEFAULT NULL COMMENT '消息Id',
-> `userId` varchar(255) DEFAULT NULL COMMENT '员工id',
-> `token` varchar(255) DEFAULT NULL COMMENT 'token',
-> `reqMsg` varchar(255) DEFAULT NULL COMMENT '请求信息',
-> `resMsg` varchar(255) DEFAULT NULL COMMENT '回复信息',
-> `createTime` datetime DEFAULT NULL COMMENT '添加时间',
-> `updateOperator` varchar(255) DEFAULT NULL COMMENT '用户',
-> `updateTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更 新时间',
-> PRIMARY KEY (`id`)
-> ) ENGINE=InnoDB AUTO_INCREMENT=3501 DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.04 sec)