软件环境 | |
---|---|
虚拟机 | VMware Workstation Pro |
操作系统 | centos7.5 |
数据库 | mysql5.7.23 |
所有操作皆在root用户下进行.
这里使用SecureCRTPortable连接虚拟机,使用SecureFXPortable上传文件.
[root@BxServer001 local]# cd /usr/local/
[root@BxServer001 local]# mkdir mysql
[root@BxServer001 local]# cd mysql/
[root@BxServer001 mysql]# tar -zxf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
[root@BxServer001 mysql]# ls
mysql-5.7.23-linux-glibc2.12-x86_64
mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
[root@BxServer001 mysql]# rm mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
rm:是否删除普通文件 "mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz"?y
[root@BxServer001 mysql]# mv mysql-5.7.23-linux-glibc2.12-x86_64/* /usr/local/mysql/
[root@BxServer001 mysql]# ls /usr/local/mysql/
bin lib share
COPYING man support-files
docs mysql-5.7.23-linux-glibc2.12-x86_64
include README
[root@BxServer001 mysql]# ls /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/
[root@BxServer001 mysql]# rm -rf /usr/local/mysql/mysql-5.7.23-linux-glibc2.12-x86_64/
[root@BxServer001 mysql]# ls
bin docs lib README support-files
COPYING include man share
[root@BxServer001 mysql]# mkdir data
[root@BxServer001 mysql]# ls
bin data include man share
COPYING docs lib README support-files
[root@BxServer001 mysql]# yum -y install libaio
[root@BxServer001 mysql]# groupadd mysql
[root@BxServer001 mysql]# useradd -M -g mysql -s /sbin/nologin -d /usr/local/mysql mysql
[root@BxServer001 mysql]# chown -R mysql.mysql /usr/local/mysql/
centos7内部集成了mariadb,而安装mysql的话会和mariadb文件冲突,所以需要先卸载mariadb,以下为卸载mariadb,安装mysql的步骤.
#列出所有被安装的rpm package
[root@BxServer001 mysql]# rpm -qa | grep maria*
mariadb-libs-5.5.56-2.el7.x86_64
[root@BxServer001 mysql]# yum -y remove mari*
已加载插件:fastestmirror
正在解决依赖关系
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.56-2.el7 将被 删除
......
...
删除:
mariadb-libs.x86_64 1:5.5.56-2.el7
作为依赖被删除:
postfix.x86_64 2:2.10.1-6.el7
完毕!
[root@BxServer001 mysql]# rm -rf /var/lib/mysql/*
[root@BxServer001 mysql]# vi /etc/my.cnf
#写入文件
[mysqld]
port=3306
character-set-server=utf8
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
#innodb_buffer_pool_size=8M
[mysqld_safe]
log-error=/usr/local/mysql/data/error.log
pid-file=/usr/local/mysql/data/mysql.pid
tmpdir = /tmp
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
#wq保存
[root@BxServer001 mysql]# ls
bin data include man share
COPYING docs lib README support-files
[root@BxServer001 mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@BxServer001 mysql]# vi /etc/init.d/mysqld
[root@BxServer001 mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
[root@BxServer001 mysql]# service mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/error.log'.
SUCCESS!
[root@BxServer001 mysql]# ./bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.23
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is 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>
mysql>SET PASSWORD FOR 'root'@localhost=PASSWORD('Your Password');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host='%' where user='root' limit 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
[root@BxServer001 mysql]# vi /etc/profile
注:最后添加
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
[root@BxServer001 mysql]# source /etc/profile
[root@BxServer001 mysql]# mysql -u root -p
[root@BxServer001 mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@BxServer001 mysql]# chkconfig --add mysqld
[root@BxServer001 mysql]# chkconfig --list mysqld
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。
mysqld 0:关 1:关 2:开 3:开 4:开 5:开 6:关
[root@BxServer001 mysql]# systemctl start mysqld
[root@BxServer001 mysql]# systemctl stop mysqld
[root@BxServer001 mysql]# systemctl status mysqld
重启服务器,测试自启服务.