1.下载好jar包;链接:https://pan.baidu.com/s/1LrKqPt4lMPcPgW4oz7JnoA
提取码:yi6m
没有配置好静态IP参考此文章
文档:centos安装,mysql .doc
链接:http://note.youdao.com/noteshare?id=38b747d0fbcd64c683591419c5bba90d&sub=FF18945C486F400CADDE864134A9C76
2.配置好静态ip后,我是用的Xshell连接,成功后会出现这样
3.然后使用rz 命令 把刚才下载好的jar包上传到根目录下
4.然后输入ls 命令就能看到上传的jar 包,注意蓝色标注的地方,刚开始上传是没有的,是解压过后的,
输入以下命令创建 文件待会解压是要用 mkdir /usr/local
[root@localhost ~]# tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
实际生产环境:
[root@localhost ~]# mv /usr/local/mysql-5.7.26-linux-glibc2.12-x86_64/ /usr/local/mysql
新增mysql用户组:
[root@localhost ~]# groupadd mysql
新增用户
[root@localhost ~]# useradd -r -g mysql mysql
给mysql 目录权限
[root@localhost ~]# cd /usr/local/
[root@localhost local]# 到初始化环境的目录
[root@localhost mysql]# mkdir log
[root@localhost mysql]# mkdir data
[root@localhost mysql]# chown -R mysql:mysql ../mysql
初始化数据和指定安装目录和数据目录
[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2019-04-19T03:23:25.059135Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-04-19T03:23:25.422900Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-04-19T03:23:25.476253Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-04-19T03:23:25.578366Z 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: 7e3573fb-6252-11e9-b2e0-000c2950fbf4.
2019-04-19T03:23:25.581778Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-04-19T03:23:25.584681Z 1 [Note] A temporary password is generated for root@localhost: We.#yr1?zbYS (找一个地方保存这个,随机生成的mysql数据库密码)
复制启动文件
[root@localhost mysql]# cd support-files/
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
[root@localhost support-files]# chmod +x /etc/init.d/mysqld
.修改启动路径
[root@localhost support-files]# vi /etc/init.d/mysqld
46 basedir=/usr/local/mysql
47 datadir=/usr/local/mysql/data
增加环境变量 (最下面添加)
[root@localhost support-files]# vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
[root@localhost support-files]# source /etc/profile
修改配置文件,输入以下命令是有可能什么都没有,如果没有,把下面这段内容辅助到该文件里面,如果有,请修改与之不同的地方
[root@localhost support-files]# vi /etc/my.cnf
[client]
port=3306
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
#socket=/usr/local/mysql/mysql.sock
socket=/tmp/mysql.sock
user=mysql
#skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/usr/local/mysql/log/mysqld.log
pid-file=/usr/local/mysql/data/mysqld.pid
#
# include all files from the config directory
#
#includedir /etc/my.cnf.d
添加开启自启
[root@localhost support-files]# chkconfig --add mysqld
[root@localhost support-files]# chkconfig mysqld on
启动
[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL.2019-04-19T03:30:21.872260Z mysqld_safe error: log-error set to '/usr/local/mysql/log/mysqld.log', however file don't exists. Create writable for user 'mysql'.
ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).
[root@localhost log]# touch mysqld.log
[root@localhost log]# chmod -R 777 /usr/local/mysql
[root@localhost data]# touch localhost.localdomain.pid
[root@localhost data]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@localhost data]# lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 49214 mysql 18u IPv6 93463 0t0 TCP *:mysql (LISTEN)
修改密码:
[root@localhost ~]# mysql -uroot -p7yT*Q?.rs>H7
mysql> set password=password("123456");
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)