mysql-5.7.26安装

 mysql-5.7.26安装

 

1、卸载mysql 相关程序

yum -y remove mysql mariadb-*
yum -y remove boost-*

2、安装相关依赖包

yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel

3、查找并删除相关mysql文件

find / -name mysql
rm -rf /etc/selinux/targeted/active/modules/100/mysql
rm -rf /usr/lib64/mysql
rm -rf /usr/share/mysql
rm -rf /usr/include/mysql

4、解压相关mysql包 

tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz  -C /usr/local/

cd /usr/local

mv mysql-5.7.26-linux-glibc2.12-x86_64/ mysql      #改mysql 解压后的名字
cd mysql
mkdir data    #建立数据库存入目录

5、建立mysql用户 (不能登录的系统用户)并赋予相关mysql目录的权限

useradd -M -s /sbin/nologin mysql

chown -R mysql:mysql /usr/local/mysql

6、修改mysql配置文件my.cnf

cat >> /etc/my.cnf <<EOF
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
user=mysql
port=3306
socket=/tmp/mysql.sock
character-set-server=utf8
log-error=/var/log/mysqld.log
pid-file=/tmp/mysqld.pid
bind-address=0.0.0.0
symbolic-links=0
EOF

 

7、建立mysql所需要配置文件以及赋予相关权限


touch /tmp/mysqld.pid

chown -R mysql:mysql /tmp/mysqld.pid

chmod 755 /tmp/mysqld.pid

touch /var/log/mysqld.log
chown -R mysql:mysql /var/log/mysqld.log
chmod 755 /var/log/mysqld.log

touch /tmp/mysql.sock

chown mysql:mysql /tmp/mysql.sock

chmod 755 /tmp/mysql.sock

 

8、初始化mysql并修改root 密码

 

cd /usr/local/mysql/bin

./mysqld  --defaults-file=/etc/my.cnf   --basedir=/usr/local/mysql  --datadir=/usr/local/mysql/data --user=mysql  --initialize 

cat /var/log/mysqld.log|grep password                    #查找初始密码  j%s!urDLX7sB

如果报错:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)

执行

./mysqld --defaults-file=/etc/my.cnf --user=root &

 

mysql -uroot -pj%s!urDLX7sB

mysql>set password=password("1qaz@wsx");      #修改密码

mysql> flush privileges;

mysql -uroot -p1qaz@wsx    #登录

9、建立开机启动

cp ./support-files/mysql.server /etc/init.d/mysqld

chown 777 /etc/my.cnf

chmod +x /etc/init.d/mysqld


ln -s /usr/local/mysql/bin/mysql /usr/bin

chkconfig --add mysqld

chkconfig --list mysqld


service mysqld start

#

Starting MySQL.. SUCCESS!

 

posted @ 2019-08-31 01:29  科子  阅读(273)  评论(0编辑  收藏  举报