mysql 安装
linux 参数调整
1.关闭numa
numactl --hardware 检查os是否开启numa
vi /boot/grub/grub.conf
default=0 timeout=5 hiddenmenu foreground=000000 background=ffffff splashimage=(hd0,0)/boot/grub/oracle.xpm.gz title Trying_C0D0_as_HD0 root (hd0,0) kernel /boot/vmlinuz-2.6.18-128.1.16.0.1.el5 root=LABEL=DBSYS ro bootarea=dbsys rhgb quiet console=ttyS0,115200n8 console=tty1 crashkernel=128M@16M numa=off initrd /boot/initrd-2.6.18-128.1.16.0.1.el5.img
重启操作系统,确认关闭
cat /proc/cmdline root=LABEL=DBSYS ro bootarea=dbsys rhgb quiet console=ttyS0,115200n8 console=tty1 crashkernel=128M@16M numa=off
使用xfs文件系统,挂载选项noatime、nodiratime、nobarrier
修改内核参数
vim /etc/sysctl.conf
vm.swappiness<=5,vm.dirty_ratio<=10, vm.dirty_background_rati<=5
1.下载mysql 5.7 二进制安装包
mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
2.解压出来
unzip mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
tar -xf mysql-5.7.19-linux-glibc2.12-x86_64.tar
3.创建mysql用户和用户组
groupadd mysql
useradd mysql -g mysql
4.创建软链接到mysql目录下。
ln -s /opt/mysql/mysql-5.7.19-linux-glibc2.12-x86_64 /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
5.修改环境变量
export PATH=$PATH:/usr/local/mysql/bin
. /root/.bash_profile
6.导入mysql配置文件my.cnf,到 /etc 目录下,修改端口及datadir
7.检查安装包
ldd mysql
8.初始化mysql,配置文件默认使用/etc/my.cnf
/usr/local/mysql/bin/mysqld --initialize
9.查找root密码
到mysql datadir 目录下有个error.log,grep password
10.启动mysql
/usr/local/mysql/bin/mysqld &
11.修改root密码
alter user user() identified by 'xxx';
简单写了个python安装脚本
#!/usr/bin/env python
import os
os.system('yum install -y libnuma* libaio*')
numa_ct=os.popen('yum list installed |grep numa|wc -l').read()
libaio_ct=os.popen('yum list installed |grep libaio|wc -l').read()
numa_ct=int(numa_ct)
libaio_ct=int(libaio_ct)
#print(libaio_ct)
#print(numa_ct)
if numa_ct < 1 :
print('no libnuma package')
exit()
if libaio_ct < 1 :
print('no libaio package')
exit()
mysql_dir=raw_input("set mysql dir \n" )
os.system('groupadd mysql ')
os.system('useradd mysql -g mysql')
##print (mysql_dir)
os.system('ln -s %s /usr/local/mysql' %(mysql_dir))
os.system('chown -R mysql:mysql /usr/local/mysql')
profile=open('/root/.bash_profile','a')
profile.write('PATH=$PATH:/usr/local/mysql/bin \n')
profile.close()
##os.system('cat /root/.bash_profile')
##os.environ['PATH']
print os.system('/usr/local/mysql/bin/mysql')
port=raw_input('set mysql port \n')
os.system('sed -i \'s/^port.*/port=%s/g\' /etc/my.cnf' %port )
os.system('sed -i \'s/^datadir.*/datadir=\/data\/mysql\/%s/g\' /etc/my.cnf' %port)
##my_cnf=open('/etc/my.cnf','a')
##my_cnf.write('port='+port+'\n')
##my_cnf.write('datadir=/data/mysql/%s' %(port))
##my_cnf.close()
os.system('mkdir -p /data/mysql/%s' %(port))
os.system('chown -R mysql:mysql /data/mysql/%s' %(port))
os.system('ldd /usr/local/mysql/bin/mysql')
os.system('/usr/local/mysql/bin/mysqld --initialize ')
print('mysql password')
os.system('cat /data/mysql/%s/error.log | grep password | awk \'{print $NF}\'' %(port))
os.system('/usr/local/mysql/bin/mysqld &')
print ('mysqldir: /usr/local/mysql ')
print ('mysqldatadir: /data/mysql/'+str(port))
--------------------------------------------------------------------------------------------
8.0安装步骤和5.7基本一致。但8.0的验证插件和5.7不一致
5.7 mysql_native_password
8.0 caching_sha2_password
此更改仅适用于安装或升级到MySQL 8.0或更高版本后创建的新帐户。对于已升级安装中已存在的帐户,其身份验证插件保持不变,还是mysql_native_password。当然也可以使用命令将用户的身份验证改为:caching_sha2_password;
ALTER USER user IDENTIFIED WITH caching_sha2_password BY 'password';
8.0的默认字符集和5.7也不一致。
5.7 utf8
8.0 utf8mb4