环境:centos7
1.创建目录
切换目录:cd /usr/local/
创建目录:mkdir mysql
2.下载mysql
切换目录:cd mysql/
下载mysql:wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
3.rpm安装mysql
rpm安装mysql:rpm -ivh mysql80-community-release-el7-1.noarch.rpm
4.安装mysql:yum -y install mysql-server
拓展:下载mysql命令:yum search mysql
安装命令:yum --installroot=/usr/local/mysql --releasever=/ -y install mysql-server
批量按时间删除文件:find /usr/local/mysql -name "*.*" -mtime -1 -exec rm {} \;
/usr/local/mysql :需要清理的指定目录
-name "*.*" :查找所有文件。若查找某一类,写法:-name "*.jpg*"
-mtime -1 :查找1天后的文件,不包含目录。-1代表1天之后,+1代表1天之前。
-exec :固定写法
{} \; :一对花括号+空格+\+分号
注意:若报错“遗漏“-exec”的参数”,请检查命令写法
批量按照文件大小查找:find . -size -2k -exec ls -l {} \;
5.配置文件
配置文件:vim /etc/my.cnf
日志文件:more /var/log/mysqld.log
服务启动脚本文件:less /usr/lib/systemd/system/mysqld.service
socket文件:vi /var/run/mysqld/mysqld.pid
6.启动服务
切换目录:cd /usr/lib/systemd/system
授权写功能:chmod +x mysqld.service
启动服务:systemctl start mysqld.service
7.设置开机自动启动:systemctl enable mysqld.service
8.查看随机密码:grep "password" /var/log/mysqld.log
9.登录mysql:mysql -u root -p
10.重置密码:alter user 'root'@'localhost' identified by 'Root@123';
11.添加远程授权权限,远程工具可连接:grant all privileges on *.* to 'root'@'%' identified by '密码' with grant option;
出现问题:
解决方法:
CREATE USER 'root'@'%' IDENTIFIED BY '密码';
GRANT ALL ON *.* TO 'root'@'%';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码';
12.刷新权限:flush privileges;
13.移除远程访问:revoke all privileges on *.* from root@localhost;
revoke grant option on *.* from root@localhost;
14.创建表空间、创建分库:create database test;
15.进入数据库:use test;
16.创建表:CREATE TABLE `mytest` (`id` int(7) NOT NULL AUTO_INCREMENT, `name` char(8) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
17.显示表:show tables;
18.插入数据:INSERT INTO `mytest` VALUES (1,'sven'),(2,'jim'),(3,'zhu'),(4,'wang'),(5,'ftd'),(6,'test'),(7,'test01'),(8,'test02'),(9,'test03');
19.查询数据:select * from test.mytest;
20.更新mysql中数据:set @RECV = 1;
select @RECV;
update mytest set name = 'qqq' where id = 1;
select @RECV;