安装
查找mysql相关安装并卸载
rpm -qa|grep -i mysql
rpm –ev {包名},如:
rpm -ev mysql-community-common-5.7.23-1.el7.x86_64
解压mysql安装包
shell> tar xzvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
shell> mv mysql-5.7.31-linux-glibc2.12-x86_64 mysql
创建文件夹
mkdir -p /software/mysql/data
mkdir -p /software/mysql/logs
mkdir -p /software/mysql/etc
安装在kamfu用户
授权chown -R kamfu:kamfu /software/mysql
在安装目录的software/mysql/etc下创建my.cnf
[mysqld]
basedir=/software/mysql
datadir=/software/mysql/data
port=3306
socket=/software/mysql/mysql.sock
log-error=/software/mysql/logs/mysqld.log
pid-file=/software/mysql/mysql.pid
server-id=1
log-bin=mysql-bin
binlog_format=mixed
symbolic-links=0
long_query_time=1
slow_query_log=ON
slow_query_log_file=/software/mysql/logs/mysql-slow.log
log_timestamps=SYSTEM
innodb_buffer_pool_size=8G
open_files_limit=65535
max_connections=2000
thread_cache_size=1024
table_open_cache=1024
/software/mysql/bin/mysqld --defaults-file=/software/mysql/etc/my.cnf --initialize --user=kamfu --basedir=/software/mysql --datadir=/software/mysql/data
进入到log查看日志
vi mysqld.log 会生成临时密码
[Note] A temporary password is generated for root@localhost: Rap&a:%hV7=1
这里会生成临时密码,在/app/mysql/err/mysqld.err文件中,第一次登录时需要用到
这里可能遇到问题:(有报错才执行)
/app/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
网上很多都是用下面这个命令安装
yum -y install numactl
export PATH=/app/software/numactl/bin:$PATH
启动mysql
安装好后,安全启动mysql
shell> /software/mysql/bin/mysqld_safe --defaults-file=/software/mysql/etc/my.cnf --user=kamfu &
ln -s /software/mysql/mysql.sock /tmp/mysql.sock
配置环境变量
在安装mysql的kamfu的用户家目录下
vi ~/.bash_profile
添加mysql环境变量
PATH=
P
A
T
H
:
PATH:
PATH:HOME/.local/bin:$HOME/bin:/software/mysql/bin
使文件生效
source ~/.bash_profile
登录更改密码
mysql -uroot -p
输入密码
mysql> set password for ‘root’@‘localhost’ = password(’*******’);
mysql> flush privileges;