mysql
mysql 安装
# Debian 10安装[参考](https://linuxize.com/post/how-to-install-mysql-on-debian-10/):
apt-get update && \
wget http://repo.mysql.com/mysql-apt-config_0.8.13-1_all.deb && \
apt -y install ./mysql-apt-config_0.8.13-1_all.deb && \
apt-get update && \
apt-get -y install mysql-server
#在163源同步的MySQL包列表 http://mirrors.163.com/mysql/Downloads/MySQL-8.0/ 中找到Ubuntu18.04的包(可以通过搜索mysql-server关键字)获取下地址
wget http://mirrors.163.com/mysql/Downloads/MySQL-8.0/mysql-server_8.0.19-1ubuntu18.04_amd64.deb-bundle.tar
mkdir mysql
tar xf mysql-server_8.0.19-1ubuntu18.04_amd64.deb-bundle.tar -C mysql/
cd mysql
apt -y install ./*.deb #安装所有的deb
apt-get -f -y install #修复依赖
mysql 默认密码
ubuntu@ubuntu:~$ sudo find / -name mysql# 查找其log位置
/var/log/mysql
ubuntu@ubuntu:~$ cat error.log |grep 'pass'
2020-05-12T04:46:04.915740Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
# 这里说使用空密码
# root用户使用进行了身份验证auth_socket。
# 将plugin更改为时mysql_native_password,我们才可以使用mysql默认密码
cat /etc/mysql/debian.cnf
user = debian-sys-maint # 配置文件登录用户与密码
password = password_for_the_user
mysql -u debian-sys-maint -p#使用debian-sys-maint用户登录
mysql> USE mysql
mysql> SELECT User, Host, plugin FROM mysql.user;
+------------------+-----------+-----------------------+
| User | Host | plugin |
+------------------+-----------+-----------------------+
| root | localhost | auth_socket |
| mysql.session | localhost | mysql_native_password |
| mysql.sys | localhost | mysql_native_password |
| debian-sys-maint | localhost | mysql_native_password |
+------------------+-----------+-----------------------+
4 rows in set (0.00 sec)
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> COMMIT; ## 将plugin更改为时mysql_native_password
mysql 5.7 修改账号密码
#mysql5.7中user表的password字段已被取消,被取代 authentication_string 字段,
# 更改用户密码也不能修改user表来实现了。
mysql> update mysql.user set authentication_string=password('123qwe') \
where user='root' and Host = 'localhost';
mysql> alter user 'root'@'localhost' identified by '123';
mysql> set password for 'root'@'localhost'=password('123');
mysql> flush privileges;
1、显示数据库列表。
show databases;
2、显示库中的数据表:
use mysql;
show tables;
3、显示数据表的结构:
describe 表名;
4、建库:
create database 库名;
5、建表:
use 库名;
create table 表名 (字段设定列表);
6、删库和删表:
drop database 库名;
drop table 表名;
7、将表中记录清空:
delete from 表名;
8、显示表中的记录:
select * from 表名
QAF
Q: ,运行出現ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)】
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &# 接著跳過授權表訪問
Q: ERROR 1698 (28000): Access denied for user ‘root’@‘localhost’
‘skip-grant-tables’>>/etc/mysql/mysql.conf.d/mysqld.cnf