目录
一、安装前准备
1、系统配置检查
--https://www.topunix.com/post-10615.html
2、环境检查
rpm -qa |grep mariadb rpm -e mariadb-5.5.56-2.el7.x86_64 --nodeps rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps rpm -e mariadb-server-5.5.56-2.el7.x86_64 --nodeps
三、安装过程
1、创建用户,组等
groupadd mysql useradd -r -g mysql -s /bin/false mysql
mkdir -p /mysql/data/3306/data mkdir -p /mysql/log/3306/binlog mkdir -p /mysql/log/3306/relaylog mkdir -p /mysql/backup/backup-db mkdir -p /backup/backup-tmp mkdir -p /backup/backup-binlog mkdir -p /mysql/app chown -R mysql:mysql /mysql/
2、下载安装程序
cd /mysql/app wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz
3、解压安装程序
cd /mysql/app/ tar xvf mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz ln -s mysql-8.0.31-linux-glibc2.12-x86_64 mysql
4、环境变量设置
vi ~/.bash_profile PATH=$PATH:$HOME/bin:/mysql/app/mysql/bin
rm -f /etc/my.cnf rm -rf /etc/my.cnf.d
(2)下载配置文件
cd /mysql/data/3306 wget https://download.topunix.com/MySQL/config-MySQL8.0/my.cnf.linux.MySQL8.0 mv my.cnf.linux.MySQL8.0 my.cnf
(3)修改参数(编辑my.cnf)
vi my.cnf
bind_address= 0.0.0.0 general_log_file=/mysql/log/3306/mysql51db-general.err slow_query_log_file=/mysql/log/3306/mysql51db-query.err log-error=/mysql/log/3306/mysql51db-error.err
(4)授权
chown -R mysql:mysql /mysql
6、初始化数据库
/mysql/app/mysql/bin/mysqld --defaults-file=/mysql/data/3306/my.cnf --initialize --user=mysql --basedir=/mysql/app/mysql --datadir=/mysql/data/3306/data
7、链接mysql.sock
ln -sf /mysql/data/3306/mysql.sock /tmp/mysql.sock
8、启动测试
(1)手动启动数据库
/mysql/app/mysql/bin/mysqld_safe --defaults-file=/mysql/data/3306/my.cnf &
(2)查看端口
netstat -nltp|grep 3306
9、设置密码# set the default password
(1)赋值随机密码至变量defaultmysqlpwd
defaultmysqlpwd=`grep 'A temporary password' /mysql/log/3306/mysql51db-error.err | awk -F "root@localhost: " '{ print $2}' |tail -n1`
(2)更改密码为rootroot
mysql -uroot -p"${defaultmysqlpwd}" --connect-expired-password <<EOF ALTER USER 'root'@'localhost' IDENTIFIED BY 'rootroot'; EOF
ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
10、通过socket方式测试创建数据库
/mysql/app/mysql/bin/mysql -uroot --password='rootroot' --socket='/mysql/data/3306/mysql.sock' -e "create database t; use t;create table t1 select 1 as a; select * from t1;drop database t;"
11、关闭数据库
(1)查看进程
ps -ef|grep mysql
(2)kill 掉mysql进程
kill -9 3456
11、自动启动配置
--https://www.topunix.com/post-11783.html#MySQL80Linux78
12、初始密码过期问题处理
--https://www.topunix.com/post-11789.html
四、创建数据库并建表等
1、创建一个数据库
create database llldb; -- CREATE DATABASE llldb default charset utf8 collate utf8_general_ci;
2、创建用户与分配权限
(1)创建用户
#创建用户时,只能用远程的方式(%),不能用localhost方式。
create user 'lll'@'%' identified by '123'; flush privileges;
(2)授权
grant all privileges on llldb.* to 'lll'@'%' identified by '1234'; grant all privileges on llldb.* to 'lll'@'localhost' identified by '12345'; --grant all privileges on *.* to 'lll'@'localhost' identified by '123456' with grant option; --grant all privileges on *.* to 'lll'@'%' identified by '1234567' with grant option; flush privileges;
3、区分上述命令的区别:
(1)授权用户lll远程访问,只能访问访问llldb数据库,同时修改访问密码为1234
grant all privileges on llldb.* to 'lll'@'%' identified by '1234';
--llldb.*中,llldb代表数据库,*代表所有表,1234代表%远程登录密码;
(2)授权用户lll本地访问,只能访问访问llldb数据库,同时修改访问密码为12345
grant all privileges on llldb.* to 'lll'@'localhost' identified by '12345';
--llldb.*中,llldb代表用户,*代表所有表,12345代表localhost本地登录密码;
(3)授权用户lll本地访问,所有库的访问权限,同时修改访问密码是123456
grant all privileges on *.* to 'lll'@'localhost' identified by '123456' with grant option;
--*.*中,第一个*代表所有数据库,*代表所有表,123456代表localhost本地登录密码;
(4)授权用户lll远程访问,所有库的访问权限,同时修改访问密码是1234567
grant all privileges on *.* to 'lll'@'%' identified by '1234567' with grant option;
--*.*中,第一个*代表所有数据库,*代表所有表,1234567代表远程登录密码;
4、删除用户
drop user lll; #默认会删除%(远程方式的)的用户 drop user 'lll'@'localhost'; #主动删除localhost方式访问的的用户
5、查看用户权限
show grants for 'lll';
6、回收权限:
把grant改为revoke,把to改为from即可。
revoke all privileges on *.* from 'lll'@'%' with grant option;
7、检查用户
select host,user from mysql.`user`;
8、创建表和数据插入
create table dept ( deptno int auto_increment primary key, dname varchar(15), loc varchar(50) ) engine = innodb; insert into dept values (1,'it','bj'); insert into dept values (2,'cw','sh'); insert into dept values (3,'hr','sz'); commit;
五、二进制MySQL卸载
1、卸载软件
停止mysql服务
删除相关目录