mysql安装方式
一、mysql 在线安装
1.查看mysql安装了哪些东西
rpm -qa |grep -i mysql
2.卸载
yum remove mysql-community-common-5.7.20-1.el7.x86_64
yum remove mysql-community-client-5.7.20-1.el7.x86_64
yum remove mysql57-community-release-el7-11.noarch
yum remove mysql-community-libs-5.7.20-1.el7.x86_64
yum removemysql-community-server-5.7.20-1.el7.x86_64
3.查找mysql相关目录
find / -name mysql
rm -rf
4.删除/etc/my.cnf
rm -rf /etc/my.cnf
5.删除/var/log/mysqld.log(如果不删除这个文件,会导致新安装的mysql无法生存新密码,导致无法登陆)
rm -rf /var/log/mysqld.log
6.安装
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
执行yum命令
yum install mysql-server
等待安装完成
若mysql命令无效,执行systemctl restart mysqld重启服务
使用cat 或者 vi /var/log/mysqld.log 查看mysql自动生成的密码
获取初始密码:cat /var/log/mysqld.log |grep password
登陆mysql:
[root@localhost ~]# mysql -u root -p
密码为上面找到的dLZMCRv?s2q)
修改root密码:
mysql> alter user 'root'@'localhost' identified by 'newpasswd';
允许远程连接:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'newpasswd' WITH GRANT OPTION;
mysql> FLUSH PEIVLEGES;
关闭防火墙:
[root@localhost ~]# systemctl stop firewalld.service
二、离线安装
1.下载 4个rpm包
mysql-community-client-5.7.26-1.el7.x86_64.rpm
mysql-community-common-5.7.26-1.el7.x86_64.rpm
mysql-community-libs-5.7.26-1.el7.x86_64.rpm
mysql-community-server-5.7.26-1.el7.x86_64.rpm
想要用迅雷进行下载得先找到对应的rpm下载路径
首先浏览器打开mysql官网:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
如下给出了4个myql5.7 的rpm包的路径,直接打开迅雷填入下载路径就可以进行下载,其他版本可以用同样方法:
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-server-5.7.26-1.el7.x86_64.rpm
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-client-5.7.26-1.el7.x86_64.rpm
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-common-5.7.26-1.el7.x86_64.rpm
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-libs-5.7.26-1.el7.x86_64.rpm
2.上传rpm到linux
我这里用的xshell,没有安装xftp
通过 rpm -ivh mysql-community-****-5.7.26-1.el7.x86_64.rpm --force --nodeps 进行安装,***表示common 、libs、client、server
安装顺序 common–>libs–>client–>server
如果没有–force --nodeps会出现告警:
warning: mysql-community-common-5.7.26-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
3.配置**
启动mysql服务 :
[root@localhost ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@localhost ~]#
找到初始密码:
[root@localhost ~]# cat /var/log/mysqld.log |grep password
2019-06-02T08:39:38.448115Z 1 [Note] A temporary password is generated for root@localhost: dLZMCRv?s2q)
2019-06-02T08:40:41.870130Z 2 [Note] Access denied for user ‘root’@‘localhost’ (using password: NO)
登陆mysql:
[root@localhost ~]# mysql -u root -p
密码为上面找到的dLZMCRv?s2q)
修改root密码:
mysql> alter user ‘root’@‘localhost’ identified by ‘newpasswd’;
允许远程连接:
mysql> GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘newpasswd’ WITH GRANT OPTION;
mysql> FLUSH PEIVLEGES;
关闭防火墙:
[root@localhost ~]# systemctl stop firewalld.service
4.更换数据文件存放目录:
(1)停止mysql服务
systemctl stop mysql
(2) MySQL 默认数据文件目录为 /var/lib/mysql,若不清楚可查看配置文件 /etc/my.cnf(也可能是 /usr/my.cnf)。
现在,我们输入以下命令,将数据文件迁移至新硬盘。如果数据文件比较大,这个过程可能会有点久。
cp -r /var/lib/mysql/ /data
(3)修改目录权限
chown -R mysql:mysql /data/mysql/
(4)新建软链接
想要迁移数据文件又不想修改配置文件,可以通过软链接实现。
输入以下命令建立软链接:
ln -s /data/mysql /var/lib/mysql
若链接成功,可以查看到如下信息:
lrwxrwxrwx 1 root root 11 Jan 16 18:11 mysql -> /data/mysql
5.重启服务
systemctl restart mysql
来源:CSDN
作者:鱼雁秋
链接:https://blog.csdn.net/qq_38613380/article/details/104892163