去mysql 官网下载 mysql 完整包
安装之前 一定要查询 系统是否有mysql
rpm -qa | grep mysql
rpm -e --nodeps XXXXXXXXx
- 解压完整包ser
tar -xvf mysql-5.7.24-1.el6.x86_64.rpm-bundle.tar
解压以后
warning: mysql-community-common-8.0.23-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
条件加上
–force --nodeps
my
# rpm -ivh mysql-community-common--5.7.24-1.el6.x86_64.rpm
# rpm -ivh mysql-community-libs--5.7.24-1.el6.x86_64.rpm
# rpm -ivh mysql-community-client--5.7.24-1.el6.x86_64.rpm
//在安装server 时 报依赖错误
rpm -ivh mysql-community-icu-data-files-8.0.28-1.el7.x86_64.rpm //要先安装这个
# rpm -ivh mysql-community-server--5.7.24-1.el6.x86_64.rpmrpm
在安装 - server文件时,经常报错
[root@libingqiang mysql]# rpm -ivh mysql-community-server-5.7.24-1.el6.x86_64.rpm
warning: mysql-community-server-5.7.24-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.24-1.el6.x86_64
libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.24-1.el6.x86_64
libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-5.7.24-1.el6.x86_64
请直接用yum 安装
#yum install numactl
安装完成以后,在执行-server 文件就可以了
- 启动数据库
# service mysqld start
# service mysqld stop
# service mysqld status
- 在数据库5.7以后,密码不是空,系统自动生成密码,在日志文件里面路径/var/log/mysqld.log 文件里 查找root@localhost: 后面跟着就是随机密码,复制粘贴一下就ok!
进入数据库以后在修改密码就行了
修改初始密码及授权远程访问:
# mysql -uroot -p
mysql> set password='Pwd@123456';
mysql> grant all privileges on *.* to 'root'@'%' identified by 'Pwd@123456';
mysql 8.0 以后不支持 grant all pri-----以上命令
命令如下
MySQL 8.0已经不支持下面这种命令写法
grant all privileges on . to root@“%” identified by “.”;
正确的写法是先创建用户
CREATE USER ‘root’@‘%’ IDENTIFIED BY ‘Hadoop3!’;
再给用户授权
https://www.runoob.com/w3cnote/mysql8-error-1410-42000-you-are-not-allowed-to-create-a-user-with-grant.html
参考上面网址
grant all privileges on . to ‘root’@‘%’ ;
密码复杂度属性:
mysql> set global validate_password_policy=0;
validate_password_policy有以下取值:(默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。)
Policy Tests Performed
0 or LOW Length
1 or MEDIUM Length; numeric, lowercase/uppercase, and special characters
2 or STRONG
Length; numeric, lowercase/uppercase, and special characters; dictionary file
修改数据目录:
新目录需要给mysql用户授权,mysqld_safe日志文件授权,关闭selinux(没找到相关策略设置的方法)
# mkdir /data/mysql/data
# mv /var/lib/mysql/* /data/mysql/data/
# mkdir /data/mysql/log
# chown mysql:mysql -R /data/mysql
# touch mysqld_safe.log
# chown mysql:mysql mysqld_safe.log
# vi /etc/my.cnf
/**
[client]
port = 3306
socket = /data/mysql/log/mysql.sock
default-character-set=utf8
[mysql]
no-auto-rehash
socket=/data/mysql/log/mysql.sock
default-character-set=utf8
[mysqld]
port = 3306
socket = /data/mysql/log/mysql.sock
character-set-server=utf8
lower_case_table_names=1
basedir=/usr
datadir=/data/mysql/data
log-error=/data/mysql/log/error.log
pid-file=/data/mysql/log/mysql.pid
init_connect='SET NAMES utf8'
symbolic-links=0
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
[mysqld_safe]
log-error=/data/mysql/log/mysqld_safe.log
*/
# getenforce
Enforcing
# setenforce 0
# vi /etc/selinux/config
/**
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
*/
# service mysqld start
其他命令:
# mysqladmin -u root -p password
mysql> select version();
# chkconfig --list
# chkconfig --level 345 mysqld on
# netstat -na | grep 3306
mysql> CREATE USER 'username'@'host' IDENTIFIED BY 'password';
# service mysqld --initedialize
Usage: /etc/init.d/mysqld {start|stop|status|restart|condrestart|try-restart|reload|force-reload}
# service mysqld start
Initializing MySQL database: [ OK ]
Installing validate password plugin: [ OK ]
Starting mysqld: exit [ OK ]
0
SQL Error [1038] [HY001]: Out of sort memory, consider increasing server sort buffer size
临时解决方案
只需运行mysql查询
SET GLOBAL sort_buffer_size = 256000000 //服务器重启后将重置
设置永久
编辑以下文件并添加
须藤nano /etc/mysql/mysql.conf.d/mysqld.cnf
sort_buffer_size = 256000000
sudo服务mysql重新启动
SET GLOBAL sort_buffer_size = 256000000 // It'll reset after server restart
To set permanent
Edit below file and add
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
sort_buffer_size = 256000000
sudo service mysql restart