当前位置:   article > 正文

CentOS7安装MySQL5.7过程以及常用需要修改操作,安装mysqlclient,安装mysql-devel报错问题以及卸载MySQL_docker centos7 mysql client dev

docker centos7 mysql client dev

Docker安装

运行命令

docker run  -p 3306:3306 --name mysql57 -v E:\\mysql\\conf:/etc/mysql/conf.d -v E:\\mysql\\data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7 --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
  • 1

mysql配置

my.cnf

[mysqld]
innodb_data_file_path=ibdata1:5M;ibdata2:5M:autoextend
bind-address                        = *
port                                = 3306
user                                = mysql
datadir                             = /var/lib/mysql
socket                              = /var/run/mysqld/mysqld.sock
pid_file                            = /var/run/mysql.pid
symbolic-links                      = 0

default-storage-engine              = InnoDB
max_allowed_packet                  = 512M
max_connections                     = 2048
open_files_limit                    = 65535

character-set-client-handshake      = FALSE
character-set-server                = utf8mb4
collation-server                    = utf8mb4_general_ci
init_connect                        = 'SET NAMES utf8mb4'

key_buffer_size = 64M

server_id = 59
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

Centos安装

下载安装

华为云镜像MySQL5.7
下载想要的版本,按照官网安装
安装

sudo yum install mysql-community-{server,client,common,libs}-*
sudo yum install mysql-community-{client,common,libs}-* mysql-5.*
  • 1
  • 2

启动

# centos
sudo service mysqld start
# 其它
sudo service mysql start
  • 1
  • 2
  • 3
  • 4

修改root用户密码

# 查看root用户临时密码
sudo grep 'temporary password' /var/log/mysqld.log
sudo grep 'temporary password' /var/log/mysql/mysqld.log
# 进入到MySQL中
mysql -uroot -p
# 更换root密码,这里注意,密码需要非常复杂,否组修改报错
ALTER USER 'root'@'localhost' IDENTIFIED BY '<MyNewPass4!>';
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

修改远程访问权限

1、改表法

use mysql;
update user set host = '%' where user = 'root';
select host, user from user;
# 使修改生效
flush privileges;
  • 1
  • 2
  • 3
  • 4
  • 5

2、授权法

GRANT ALL PRIVILEGES ON *.* TO '<myuser>'@'%' IDENTIFIED BY '<rootpassword>' WITH GRANT OPTION;
  • 1

MySQL密码验证

SHOW VARIABLES LIKE 'validate_password%';
# 安装和卸载密码验证
INSTALL PLUGIN validate_password SONAME 'validate_password.so';
uninstall plugin validate_password;
# 设置密码验证
SET GLOBAL validate_password_policy=LOW;
SET GLOBAL validate_password_length = 4;
SET GLOBAL validate_password_policy = 0;
SET GLOBAL validate_password_mixed_case_count = 0;
SET GLOBAL validate_password_number_count = 0;
SET GLOBAL validate_password_special_char_count = 0;
SET GLOBAL validate_password_check_user_name = 0;
FLUSH PRIVILEGES;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

mysqlclient时候报错 OSError: mysql_config not found

原因就是找不到mysql-config,需要安装mysql-devel解决,但是博主在安装时,报错mariadb报错,查看版本,mariadb5.5,MySQL5.7,猜测可能是这个原因导致,卸载mariadb后,成功运行。装的是官网的安装包mysql-devel

# 查看yum安装列表
yum list installed | grep mariadb
# 卸载
yum erase <name>
  • 1
  • 2
  • 3
  • 4

要知道一些原理,不要直接按照网上的博文操作,尤其国内的

yum install mysql-devel
yum install mariadb-dev
  • 1
  • 2

卸载MySQL

# 查看mysql安装了哪些东西,卸载
rpm -qa |grep -i mysql
yum remove <name>
# 直接全部卸载
rpm -qa |grep -i mysql|xargs yum remove -y
# 查找文件
find / -name mysql
# 删除
rm -rf <name>
# 删除/etc/my.cnf
rm -rf /etc/my.cnf
# 删除/var/log/mysqld.log(如果不删除这个文件,会导致新安装的mysql无法生存新密码,导致无法登陆)
rm -rf /var/log/mysqld.log
# 注意log的位置可能不同

# 删除mariadb-libs,再安装包
yum remove mariadb-libs
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

binlog

[mysqld]
log-bin=mysql-bin
server-id=1234
  • 1
  • 2
  • 3

参考链接:
解决MySQL不允许(其它IP)从远程访问的方法
Your password does not satisfy the current policy requirements
官网关于密码验证
Centos7 完全卸载mysql

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/537440
推荐阅读
相关标签
  

闽ICP备14008679号