dpkg --list|grep mysql
sudo apt-get remove mysql-common
sudo apt-get autoremove --purge mysql-server
dpkg -l|grep ^rc|awk '{print$2}'|sudo xargs dpkg -P
sudo apt-get update
sudo apt-get install mysql-server
systemctl status mysql.service
show global variables like '%general%';
sudo mysql_secure_installation
set global validate_password_policy=0;
默认密码在cat /etc/mysql/debian.cnf
update mysql.user set authentication_string=password('root') where user='root' ;
#或
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'bapebape';
GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "123456";
flush privileges;
select Host, User,authentication_string,plugin from mysql.user;
grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口令’;
权限1,权限2,…权限n代表:select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14个权限。
当数据库名称.表名称被*代替,表示赋予用户操作服务器上所有数据库所有表的权限。
用户地址可以是localhost,也可以是ip地址、机器名字、域名。也可以用’%'表示从任何地址连接。
'连接口令’不能为空,否则创建失败。
update mysql.user set plugin="mysql_native_password" where user='root';
auth_socket 验证插件的使用场景
问题解决后,又仔细研究了一下 auth_socket 这个插件,发现这种验证方式有以下特点:
首先,这种验证方式不要求输入密码,即使输入了密码也不验证。这个特点让很多人觉得很不安全,实际仔细研究一下这种方式,发现还是相当安全的,因为它有另外两个限制;
只能用 UNIX 的 socket 方式登陆,这就保证了只能本地登陆,用户在使用这种登陆方式时已经通过了操作系统的安全验证;
操作系统的用户和 MySQL 数据库的用户名必须一致,例如你要登陆 MySQL 的 root 用户,必须用操作系统的 root 用户登陆。
vi /etc/mysql/my.cnf
注释掉 bind-address= 127.0.0.1
就可以远程访问了。
show variables like '%secure%';
grant all privileges on 库名.表名 to xx@"%" identified by "密码";`
vi /etc/mysql/mysql.conf.d/mysqld.cnf
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
create database database_name charset utf8mb4;
use database_name;
create table table_name(id text,ip text) charset utf8mb4;
create table table_name2 as select * from table_name1 where 1=2
`DROP TABLE 表名1,表名2,表名3...`
TRUNCATE database/table 库/表名
alter table t_book rename to bbb;
desc 表名;
load data local infile '/var/lib/mysql-files/platon/a.txt' into table users;
select * from table_name into outfile '/var/lib/mysql-files/file_name.xls';
alter table 表名 add column 列名 varchar(30) AFTER `某列`;
alter table 表名 add column 列名 varchar(30) first;
alter table 表名 drop column 列名;
#MySQL:
alter table bbb change nnnnn hh int;
#SQLServer:
exec sp_rename't_student.name','nn','column';
#Oracle:
lter table bbb rename column nnnnn to hh int;
alter table t_book modify name varchar(22);
alter table 表名 modify 列 first;
alter table 表名 modify 列 字段类型 after 列;
update 表 set 列=值 where nodeid=99;
insert into 表名 (字段1,字段2,...字段n) VALUES (值1,值2,...值n);
insert into table_name2 select * from table_name1;
DELETE FROM table_1 WHERE cloumn=value;
update table_1 set column_1 = xxx where column_2 = xxx;
根据条件把表2数据更新至表1
update table_1 t1,table_2 t2 set t1.column = t2.column where t1.id = t2.pid;
嵌套语句
UPDATE
table_a ta,(SELECT tb_value1,tb_value2 FROM table_b WHERE tb_value3 = 'value3') tb
SET ta.ta_value1 = tb.tb_value1
WHERE ta.ta_value2 = tb.tb_value2;
select * from table_1 where cloumn_1=value_1 and cloumn_2=value2;
%匹配单个字符
select * from table_1 where cloumn_1 like %value_1%;
select ip from table_1 A where A.id not in (select id from table_2);
单列排序
SELECT * FROM test1 ORDER BY date_time
频数频率统计
SELECT
COALESCE(a.city,'total') AS 'city',
COUNT(a.city) AS 'count(city)',
COUNT(a.city)/(SELECT count(*) FROM nodeip)*100 AS '%(city)'
FROM
nodeip AS a
GROUP BY
a.city
ORDER BY
count(city);