centos-mysql8.0 安装
系统环境:CentOS7.4 最小化安装
zabbix添加用户的方式不一样了,这里贴一下:
create database zabbix character set utf8 collate utf8_bin; create user 'zabbix'@'localhost' identified by 'yanqi'; grant all privileges on zabbix.* to 'zabbix'@'localhost' with grant option;
1、前期准备
yum -y install automake libtool libaio #解压 tar xf mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz -C /opt cd /opt mv mysql-8.0.31-linux-glibc2.12-x86_64 mysql #创建目录及用户 useradd mysql -s /sbin/nologin -u 1800 mkdir /opt/mysql/data chown -R mysql.mysql /opt/mysql/ chmod 750 /opt/mysql/data -R #环境变量 cat >> /etc/profile << 'EOF' export PATH=$PATH:/opt/mysql/bin:/opt/mysql/lib EOF #新增如下文件 cat >> /etc/my.cnf << 'EOF' mysql] default-character-set=utf8mb4 [client] socket=/var/lib/mysql/mysql.sock [mysqld] user=mysql general_log = 1 general_log_file= /var/log/mysql/mysql.log socket=/var/lib/mysql/mysql.sock basedir=/opt/mysql/ datadir=/opt/mysql/data character-set-server=utf8mb4 default_authentication_plugin=mysql_native_password #skip-grant-tables #免密登录mysql sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION" EOF
2、编译安装
cd /opt/mysql/bin/
./mysqld --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data/ --initialize
最后一行会现实密码:
3、启动命令
[root@db01 bin]# cp -a ../support-files/mysql.server /etc/init.d/mysql [root@db01 bin]# cp -a ../support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysql chmod +x /etc/init.d/mysqld #有就备份走,没有新建 mkdir /var/lib/mysql chown -R mysql:mysql /var/lib/mysql/ #启动 service mysql start systemctl enable mysql
4、修改远程密码或忘记密码重置
# 修改root远程
mysql -u root -p
use mysql;
update user set Host='%' where User='root';
flush privileges;
#修改密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Wow656&Nod';
flush privileges;
#1、如忘记密码则去掉my.cnf文件中配置项 #skip-grant-tables 前的#号;重启mysql服务:
service mysql restart
service mysql stop
service mysql status
#2、登录成功,修改密码:
mysql -uroot -p
use mysql;
5、查看并修改用户信息
#查看添加的用户信息 use mysql; select host, user from user; #创建一个新用户,并赋予全部权限 CREATE USER 'hive'@'%' IDENTIFIED BY 'hive'; GRANT ALL ON *.* TO 'hive'@'%'; #授权用户读写指定表 GRANT ALL ON xianzyk.source_user_department TO 'hive'@'%'; #修改用户密码 alter user 'hive'@'%' identified by '84f6P8h@M'; flush privileges;
6、备份数据库及导入表
备份数据库: mysqldump -uroot -p xianzyk > /mysqlbakup/xianzyk.bak.sql #导表 mysql -uroot -p use xianzyk; show tables; //该库中有哪些表(授权可看到的) mysql> source /root/source_user_department.sql //如要导入多表,可多次执行 Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected, 1 warning (0.00 sec) Query OK, 0 rows affected, 6 warnings (0.03 sec) Query OK, 0 rows affected (0.00 sec)
8、最终效果
python3