Linux下mysql的配制文件在/etc/my.cnf
mysql下载路径:
https://dev.mysql.com/downloads/mysql/
1.查看自己Linux系统版本:
cat /etc/RedHat-release
2.往下拉继续选择,根据自己系统相应的版本选择下载:(这里以MySQL5.7.20为例,可下载实时最新版本)
a.相关支持:
perl-Data-Dumper-2.145-3.el7.x86_64.rpm
libaio-0.3.109-13.el7.x86_64.rpm
net-tools-2.0-0.22.20131004git.el7.x86_64.rpm
perl-Data-Dumper-2.145-3.el7.x86_64.rpm下载路径:
http://mirror.centos.org/centos/7/os/x86_64/Packages/perl-Data-Dumper-2.145-3.el7.x86_64.rpm
libaio-0.3.109-13.el7.x86_64.rpm下载路径:
http://mirror.centos.org/centos/7/os/x86_64/Packages/libaio-0.3.109-13.el7.x86_64.rpm
net-tools-2.0-0.22.20131004git.el7.x86_64.rpm下载路径:
http://mirror.centos.org/centos/7/os/x86_64/Packages/net-tools-2.0-0.22.20131004git.el7.x86_64.rpm
perl-Data-Dumper-2.145-3.el7.x86_64.rpm 、libaio-0.3.109-13.el7.x86_64.rpm和net-tools-2.0-0.22.20131004git.el7.x86_64.rpm
rpm -ivh libaio-0.3.109-13.el7.x86_64.rpm
rpm -ivh perl-Data-Dumper-2.145-3.el7.x86_64.rpm
rpm -ivh net-tools-2.0-0.22.20131004git.el7.x86_64.rpm
rpm -qa | grep mariadb
rpm -e --nodeps 查出来的相应的文件
tar -xf mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
rpm -ivh mysql-community-common-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-*
rpm -ivh mysql-community-devel-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
至此,mysql安装成功
systemctl start mysqld.service
systemctl status mysqld.service
systemctl stop mysqld.service
cat /var/log/mysqld.log | grep password
输入该命令后出现以下内容:
2017-11-04T05:56:08.454323Z 1 [Note] A temporary password is generated for root@localhost: ps1DY?%T.Vc4(这里为root初始随机密码,注意:这里是事例,登录时要填入自己系统产生的密码)
mysql -u root -p
输入刚才查到的初始密码(复制即可),登录成功后发现输入任何命令都会提示你需要修改初始密码,所以接下来要修改初始密码。
(注意:在MySQL数据库每次输入完命令后要加;)
set global validate_password.policy=0;
set global validate_password.length=1;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'KL1f~xXal8';
ALTER USER USER() IDENTIFIED BY 'Xiaoming250';
SET PASSWORD = PASSWORD('Q7sg=icKfz');
MySQL修改用户的密码主要有两种方法:ALTER USER 和SET PASSWORD
ALTER USER
基本使用
ALTER USER testuser IDENTIFIED BY '123456';
修改当前登录用户(自己操作时用了这个命令,注意需要用当前用户登陆)
ALTER USER USER() IDENTIFIED BY '123456';
使密码过期
ALTER USER testuser IDENTIFIED BY '123456' PASSWORD EXPIRE;
使密码从不过期
ALTER USER testuser IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
按默认设置过期时间
ALTER USER testuser IDENTIFIED BY '123456' PASSWORD EXPIRE DEFAULT;
指定过期间隔
ALTER USER testuser IDENTIFIED BY '123456' PASSWORD EXPIRE INTERVAL 90 DAY;
在MySQL文档里,推荐使用ALTER USER修改用户密码
SET PASSWORD
使用SET PASSWORD的password有两种:
使用默认加密
SET PASSWORD FOR testuser = '123456'
使用PASSWORD()函数加密
SET PASSWORD FOR testuser = PASSWORD("123456")
注意:使用PASSWORD('auth_string')的方式已经被废弃,在以后的版本会把它移除,所以不建议使用它来修改密码。
FLUSH PRIVILEGES;
至此数据库安装完毕,再输入相应命令就没有问题了
1. 通过命令进入mysql数据库,然后输入命令进入mysql数据库:
use mysql;
2. 登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改成"%" :
update user set host = '%' where user = 'root';
注意:(用户名可以根据实际情况自己指定)
3. 查看root用户修改结果:
select host, user from user;
4. 刷新:
FLUSH PRIVILEGES;
5. 远程连接问题
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root@123' WITH GRANT OPTION;
find / -iname '*.cnf' -print
CREATE USER `test_zl`@`127.0.0.1` IDENTIFIED BY 'KL1f~xXal9';
CREATE DATABASE `test_zl` CHARACTER SET 'utf8' COLLATE 'utf8_bin';
1.用root用户进入shell: mysql -h127.0.0.1 -uroot -proot
2.创建数据库:create database front character set utf8 collate utf8_bin;
3.授权数据库: grant all on front.* to front@'%'IDENTIFIED BY 'front';
如果是mysql8 需要用以下授权方法:
create user 'front'@'%' identified by 'front'
grant all privileges on middle.* to 'middle'@'%';
4.权限生效: flush privileges;
5.GRANT Alter, Alter Routine, Create, Create Routine, Create Temporary Tables, Create User, Create View, Delete, Drop, Event, Execute, File, Grant Option, Index, Insert, Lock Tables, Process, References, Reload, Replication Client, Replication Slave, Select, Show Databases, Show View, Shutdown, Super, Trigger, Update ON *.* TO `test_zl`@`127.0.0.1`;
10.参考网址
3. MySQL无外网安装过程:
https://www.linuxidc.com/Linux/2017-11/148286.htm
4. MySQL修改密码复杂度:
https://www.cnblogs.com/ivictor/p/5142809.html
5. MySQL解决远程连接问题:
https://jingyan.baidu.com/article/455a9950a4fea0a16727787e.html
6. MySQL创建新用户并授权:
https://www.jb51.net/article/31850.htm
查询mysql相应安装信息:rpm -qa | grep mysql
删除命令:
rpm -ev MySQL-client-5.5.25a-1.rhel5
rpm -ev MySQL-server-5.5.25a-1.rhel5
如果上述命令未能删除可如下:
rpm -ev MySQL-client-5.5.25a-1.rhel5 --nodeps
再次查询:rpm -qa | grep mysql
以下是删除的截图
find / -name mysql
查找结果如下:
/var/lib/mysql
/var/lib/mysql/mysql
/etc/selinux/targeted/active/modules/100/mysql
执行删除命令:
rm -rf /var/lib/mysql
rm -rf /var/lib/mysql/mysql
rm -rf /etc/selinux/targeted/active/modules/100/mysql
find / -iname '*.cnf' -print
rm -rf /etc/my.cnf
最后再执行检查:rpm -qa|grep -i mysql
如果没有了,说明卸载干净了
运维给了两台新环境,结果装完Mysql后跑了两天kafka就堵了,追查发下,是因为业务处理时,mysql数据所在的磁盘满了,只给分了1.9个G是个什么鬼啊。另一块200G的没有挂载,mysql是默认安装没记得有路径需要改,发现文件记在了/var/lib/mysql下,100%了,就是这个原因导至了kafka积累。干~~~ 修改mysql datadir,或是把文件重新挂载,先unmount 再mount
find / -iname '*.cnf' -print
修改之前长这样
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
修改后的样子如下:
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[client]
socket=/data/mysql/mysql.sock
注:上面的[client] socket=/data/mysql/mysql.sock如果不加的话,启动后无法用mysql -uroot -ppassword登陆,会报错ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ;总之默认通过systemctl start mysql 后,用mysql 命令会找到默认路径/var/lib/mysql/mysql.sock下。所以需要在配制文件中显示声明出来就好了。
把已有的数据文件copy到指定路径,并创建log文件夹
cp -rf /var/lib/mysql /data/mysql
mkdir /data/log
(cp -a /var/lib/mysql /data/ )
(chown -R mysql:mysql /data/mysql)
(chown -R mysql:mysql /data)
rm -rf /var/lib/limb
systemctl stop mysqld.service
systemctl start mysqld.servcie