1、创建mysql文件夹:mkdir /usr/local/mysql 用于存放MySQL安装包
下载链接:https://pan.baidu.com/s/1qfLS8_KjbzQoMHgSmxYkfg
提取码:va73
2、通过客户端工具Xftp把我们保存在windows上的mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar传输到刚在Linux中创建的mysql文件夹下,如下图所示:
3、解压tar文件到指定目录:tar -xvf mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar -C /usr/local/mysq
4、卸载冲突的RPM组件
在我们安装mysql相关组件的时候,如果不将此冲突的组件删除掉,我们是安装不成功的。
查看postfix和mariadb-libs相关的组件:
rpm -qa | grep postfix
rpm -qa | grep mariadb
卸载postfix和mariadb-libs:
rpm -ev postfix-2.10.1-6.el7.x86_64
rpm -ev mariadb-libs-5.5.52-1.el7.x86_64
5、安装相应的依赖 :
yum -y install libaio
yum -y install net-tools
yum -y install perl
6、 安装mysql组件
经过上面的解压操作,我们得到了很多rpm文件。但是我们不需要这么多,我们只需要安装以下四个组件就可以了:
mysql-community-common-5.7.23-1.el7.x86_64.rpm
mysql-community-libs-5.7.23-1.el7.x86_64.rpm
mysql-community-client-5.7.23-1.el7.x86_64.rpm
mysql-community-server-5.7.23-1.el7.x86_64.rpm
因为具有依赖关系,所以我们需要按顺序执行。
用 rpm -ivh 文件名 就能安装相应的组件。(这里安装到指定目录)
在执行server的时候,需要依赖安装一些工具组件,已经在上文有说明了安装命令
rpm -ivh --prefix= /usr/local/mysql mysql-community-common-5.7.19-1.el7.x86_64.rpm
rpm -ivh --prefix= /usr/local/mysql mysql-community-libs-5.7.19-1.el7.x86_64.rpm
rpm -ivh --prefix= /usr/local/mysql mysql-community-client-5.7.19-1.el7.x86_64.rpm
rpm -ivh --prefix= /usr/local/mysql mysql-community-server-5.7.19-1.el7.x86_64.rpm --nodeps
如果出现报错:在linxu下如果在执行
bin/mysqld --initialize --user=mysql
出错并报
./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
的意思是缺少libnuma依赖.我们可以通过安装yum install -y libnuma来解决这个问题
解决方法(一):
安装:numactl
下载地址:http://mirror.centos.org/centos/6/os/x86_64/Packages/numactl-2.0.9-2.el6.x86_64.rpm
解决方法(二):
用yum装yum -y install numactl
安装rpm包 :mysql-community-client-5.7.13-1.el7.x86_64.rpm报错如下:
/home/mysql>sudo rpm -ivh
mysql-community-client-5.7.13-1.el7.x86_64.rpm [sudo] password for
*****: warning: mysql-community-client-5.7.13-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY error: Failed
dependencies:
mysql-community-libs(x86-64) >= 5.7.9 is needed by mysql-community-client-5.7.13-1.el7.x86_64
mariadb is obsoleted by mysql-community-client-5.7.13-1.el7.x86_64解决办法: 安装包后面增加2个参数(安装时不再分析包之间的依赖关系而直接安装)
/home/mysql>sudo rpm -ivh
mysql-community-client-5.7.13-1.el7.x86_64.rpm --nodeps --force [sudo]
password for ******: warning:
mysql-community-client-5.7.13-1.el7.x86_64.rpm: Header V3 DSA/SHA1
Signature, key ID 5072e1f5: NOKEY Preparing…
################################# [100%] Updating / installing… 1:mysql-community-client-5.7.13-1.e##################### (
63%)
7 启动mysql并设置开机自启
[root@hadoop03 ~]# systemctl start mysqld
[root@hadoop03 ~]# systemctl enable mysqld
[root@hadoop03 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: activating (start-pre) since Mon 2019-08-26 20:11:52 CST; 19s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 26300 (code=killed, signal=KILL); : 27762 (mysqld_pre_syst)
CGroup: /system.slice/mysqld.service
└─control
├─27762 /bin/bash /usr/bin/mysqld_pre_systemd
└─27806 /usr/bin/python -Es /usr/sbin/semanage fcontext -a -e /var/lib/mysql /var/lib/my...
Aug 26 20:11:52 hadoop03 systemd[1]: Starting MySQL Server...
[root@hadoop03 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2019-08-26 20:12:41 CST; 27s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 32360 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 27762 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 32390 (mysqld)
CGroup: /system.slice/mysqld.service
└─32390 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Aug 26 20:12:39 hadoop03 mysqld[32360]: 2019-08-26T12:12:39.420832Z 0 [Note] InnoDB: Buffer pool(...2:39
Aug 26 20:12:39 hadoop03 mysqld[32360]: 2019-08-26T12:12:39.439210Z 0 [Note] Found ca.pem, server...hem.
Aug 26 20:12:39 hadoop03 mysqld[32360]: 2019-08-26T12:12:39.494362Z 0 [Warning] CA certificate ca...ned.
Aug 26 20:12:39 hadoop03 mysqld[32360]: 2019-08-26T12:12:39.511734Z 0 [Note] Server hostname (bin...3306
Aug 26 20:12:39 hadoop03 mysqld[32360]: 2019-08-26T12:12:39.511827Z 0 [Note] IPv6 is available.
Aug 26 20:12:39 hadoop03 mysqld[32360]: 2019-08-26T12:12:39.511841Z 0 [Note] - '::' resolves to '::';
Aug 26 20:12:39 hadoop03 mysqld[32360]: 2019-08-26T12:12:39.511863Z 0 [Note] Server socket create...::'.
Aug 26 20:12:40 hadoop03 mysqld[32360]: 2019-08-26T12:12:40.927098Z 0 [Note] Event Scheduler: Loa...ents
Aug 26 20:12:40 hadoop03 mysqld[32360]: 2019-08-26T12:12:40.955064Z 0 [Note]
Aug 26 20:12:41 hadoop03 systemd[1]: Started MySQL Server.
Aug 26 20:13:33 hadoop03 systemd[1]: mysqld.service: main process exited, code=killed, status=9/KILL
Aug 26 20:13:33 hadoop03 systemd[1]: Unit mysqld.service entered failed state.
Aug 26 20:13:33 hadoop03 systemd[1]: mysqld.service failed.
Aug 26 20:13:33 hadoop03 systemd[1]: mysqld.service holdoff time over, scheduling restart.
Aug 26 20:13:33 hadoop03 systemd[1]: Stopped MySQL Server.
Aug 26 20:13:33 hadoop03 systemd[1]: Starting MySQL Server...
Hint: Some lines were ellipsized, use -l to show in full.
8、修改MySQL密码
mysql安装完成之后我们是没有设置密码的,但是mysql为我们设置了一个临时的密码,我们可以查看mysql的日志知道这个临时密码,查看临时密码前确保数据库启动。
(1)启动数据库
查看mysql是否启动:service mysqld status
启动mysql:service mysqld start
停止mysql:service mysqld stop
重启mysql:service mysqld restart
(2)查看临时密码:grep password /var/log/mysqld.log
这样我们得知临时密码是: #BRm.Mi/s6.i,然后我们用这个临时密码登录数据库。(数据库的密码需要满足以下条件:大小写字母,数字和特殊符号)
登录mysql(命令:mysql -p),输入临时密码
设置新密码:set password = password(“Mysql_123”);
退出当前登录:quit;
重新登录,此时就能用新密码登录了,然后就可以进行数据库操作了。
8、允许远程连接
开启mysql远程访问权限,允许远程连接
mysql -u root -p
use mysql;
update user set host = ‘%’ where user = ‘root’;
flush privileges;
9、创建数据库,并指定UTF-8编码
CREATE DATABASE 数据库名 CHARACTER SET utf8 COLLATE utf8_general_ci;
10、命令行导入数据库
mysql -h localhost -u root -p 数据库名< /home/fps001.sql
11、命令行导出数据库
mysqldump -h localhost -u root -p 数据库名> /home/fps001.sql