安装前查看有无旧mysql文件影响,若有删除
[root@localhost ~]# find / -name mysql
/usr/lib64/mysql
/usr/share/mysql
[root@localhost ~]# rm -rf /usr/lib64/mysql /usr/share/mysql
[root@localhost ~]# find / -name mysql
安装文件传输工具
[root@localhost ~]# yum install -y lrzsz
已经在在电脑本地下载好安装包,用文件传输工具传到虚拟机,/usr/local/src下
[root@localhost ~]# rz
rz waiting to receive.
zmodem trl+C ȡ100% 638679 KB 15577 KB/s 00:00:41 0 Errorsc2.5-x86_64.tar.gz...
[root@localhost src]# ls
mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
解压,并移命令到/usr/local/mysql目录下
[root@localhost src]# tar -zxf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
[root@localhost src]# mv mysql-5.7.17-linux-glibc2.5-x86_64 /usr/local/mysql
创建mysql数据库
[root@localhost mysql]# mkdir -p /data/mysql
创建mysql用户、组、目录
[root@localhost mysql]# groupadd mysql
[root@localhost mysql]# useradd-s /sbin/nologin -g mysql -d /usr/local/mysql/ mysql #指定shell,组,目录
更改所需目录的属性
[root@localhost mysql]# chown -R mysql:mysql /usr/local/mysql/[root@localhost mysql]# chown-R mysql:mysql /data/mysql/
初始化
[root@localhost mysql]# bin/mysqld --initialize --uesr=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared objectfile: No such file or directory
[root@localhost mysql]# yum install-y libaio
[root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql2019-03-08T12:45:57.795709Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation formore details).2019-03-08T12:45:58.002925Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-03-08T12:45:58.032593Z 0[Warning] InnoDB: Creating foreign key constraint system tables.2019-03-08T12:45:58.095016Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 1eed45e3-41a0-11e9-9604-000c298ea755.2019-03-08T12:45:58.097609Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed'cannot be opened.2019-03-08T12:45:58.099193Z 1 [Note] A temporary password is generated for root@localhost: *lisitQl=6xt
配置文件
[root@localhost mysql]# cd support-files/[root@localhost support-files]# cp my-default.cnf /etc/my.cnf
[root@localhost support-files]# cp mysql.server /etc/init.d/mysql
[root@localhost support-files]# vi /etc/init.d/mysql
basedir=/usr/local/mysql
datadir=/data/mysql
启动mysql,更改密码[root@localhost support-files]# cd ..
密码*lisitQl=6xt
[root@localhost support-files]# cd ..
[root@localhost mysql]# bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection idis 3Server version:5.7.17Copyright (c)2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracleis a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type'help;' or '\h' for help. Type '\c'to clear the current input statement.
mysql> set password=password('root');
Query OK,0 rows affected, 1 warning (0.00sec)
mysql>flush privileges; #刷新mysql相关表
Query OK,0 rows affected (0.00sec)
mysql>quit
Bye
添加系统路径,添加启动项
[root@localhost mysql]# vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin #添加该行[root@localhost mysql]# source/etc/profile
[root@localhost mysql]# chkconfig --add mysql
启动mysql
[root@localhost ~]# service mysql stop
Shutting down MySQL.. SUCCESS!