CentOS-7安装MySQL

网易镜像

http://ftp.ntu.edu.tw/MySQL/Downloads/MySQLInstaller/

一、MySQL官网获取下载地址

当我们需要安装MySQL的某一个版本的时候,访问MySQL的官网:https://www.mysql.com/->DOWNLOADS->Archives->MySQL Community Server,选择版本,操作系统,操作系统版本,下载RPM Bundle。这个时候获取到 下载 地址:https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar

二、下载和解压

wget -c https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar

tar vxf mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar

解压后的文件RPM文件列表:

mysql-community-libs-5.7.20-1.el7.x86_64.rpm
mysql-community-client-5.7.20-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm
mysql-community-common-5.7.20-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.20-1.el7.x86_64.rpm
mysql-community-devel-5.7.20-1.el7.x86_64.rpm
mysql-community-server-5.7.20-1.el7.x86_64.rpm
mysql-community-embedded-5.7.20-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.20-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.20-1.el7.x86_64.rpm
mysql-community-test-5.7.20-1.el7.x86_64.rpm

mysql-community-embedded-devel-5.7.20-1.el7.x86_64.rpm

三、安装

yum localinstall mysql-community-common-5.7.20-1.el7.x86_64.rpm

yum localinstall mysql-community-libs-5.7.20-1.el7.x86_64.rpm

yum localinstall mysql-community-client-5.7.20-1.el7.x86_64.rpm

yum localinstall mysql-community-server-5.7.20-1.el7.x86_64.rpm

当安装common的时候,遇到冲突的时候用yum remove mariadb-libs-1:5.5.56-2.el7.x86_64或者rpm -e mariadb-libs-1:5.5.56-2.el7.x86_64卸载冲突包。

[x@localhost ~]$ sudo yum localinstall mysql-community-common-5.7.20-1.el7.x86_64.rpm 
[sudo] password for x: 
Loaded plugins: fastestmirror
Examining mysql-community-common-5.7.20-1.el7.x86_64.rpm: mysql-community-common-5.7.20-1.el7.x86_64
Marking mysql-community-common-5.7.20-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-common.x86_64 0:5.7.20-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================
 Package                          Arch             Version                   Repository                                             Size
=========================================================================================================================================
Installing:
 mysql-community-common           x86_64           5.7.20-1.el7              /mysql-community-common-5.7.20-1.el7.x86_64           2.5 M

Transaction Summary
=========================================================================================================================================
Install  1 Package

Total size: 2.5 M
Installed size: 2.5 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test


Transaction check error:
  file /usr/share/mysql/czech/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/danish/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/dutch/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/english/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/estonian/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/french/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/german/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/greek/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/hungarian/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/italian/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/japanese/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/korean/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/norwegian-ny/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/norwegian/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/polish/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/portuguese/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/romanian/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/russian/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/serbian/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/slovak/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/spanish/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/swedish/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/ukrainian/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/Index.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/armscii8.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/ascii.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/cp1250.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/cp1256.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/cp1257.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/cp850.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/cp852.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/cp866.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/dec8.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/geostd8.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/greek.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/hebrew.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/hp8.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/keybcs2.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/koi8r.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/koi8u.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/latin1.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/latin2.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/latin5.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/latin7.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/macce.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/macroman.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64
  file /usr/share/mysql/charsets/swe7.xml from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.56-2.el7.x86_64

Error Summary
-------------

 

[x@localhost ~]$ sudo yum remove mariadb-libs-1:5.5.56-2.el7.x86_64
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Running transaction check
---> Package postfix.x86_64 2:2.10.1-6.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================
 Package                           Arch                        Version                              Repository                      Size
=========================================================================================================================================
Removing:
 mariadb-libs                      x86_64                      1:5.5.56-2.el7                       @anaconda                      4.4 M
Removing for dependencies:
 postfix                           x86_64                      2:2.10.1-6.el7                       @anaconda                       12 M

Transaction Summary
=========================================================================================================================================
Remove  1 Package (+1 Dependent package)

Installed size: 17 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : 2:postfix-2.10.1-6.el7.x86_64                                                                                         1/2 
  Erasing    : 1:mariadb-libs-5.5.56-2.el7.x86_64                                                                                    2/2 
  Verifying  : 1:mariadb-libs-5.5.56-2.el7.x86_64                                                                                    1/2 
  Verifying  : 2:postfix-2.10.1-6.el7.x86_64                                                                                         2/2 

Removed:
  mariadb-libs.x86_64 1:5.5.56-2.el7                                                                                                     

Dependency Removed:
  postfix.x86_64 2:2.10.1-6.el7                                                                                                          

Complete!

三、修改root本地密码

 

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:

grep 'temporary password' /var/log/mysqld.log

进入MySQL:

mysql -u root -p

查看密码策略

show variables like '%password%'

设置密码策略:

set global validate_password_policy=0;

查看密码策略:

select @@validate_password_policy;

设置密码长度:

set global validate_password_length=4;

查看密码长度:

select @@validate_password_length;

然后你就可以将你的密码改为简单的密码。

alter user 'root'@'localhost' identified by '123456';

或者

set password for 'root'@'localhost'='123456';

此set password for 'root'@'localhost'=password('123456');命令将被弃用。

允许远程访问

grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;

grant all on *.* to 'root'@'%';

其中123456为你的访问密码。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在CentOS 7上通过源码安装MySQL的详细步骤: 1. 准备编译环境: - 确保系统已安装必要的编译工具,使用以下命令安装: ``` sudo yum groupinstall "Development Tools" ``` - 安装其他依赖项: ``` sudo yum install cmake ncurses-devel ``` 2. 下载MySQL源码: - 访问MySQL官方网站(https://dev.mysql.com/downloads/mysql/),找到并下载适合您系统的MySQL源码。 3. 解压源码包: - 在终端中,进入下载目录,然后执行以下命令解压: ``` tar xf mysql-<version>.tar.gz ``` 4. 创建MySQL安装目录: - 在终端中,执行以下命令创建一个目录作为MySQL安装目录(例如:/usr/local/mysql): ``` sudo mkdir /usr/local/mysql ``` 5. 编译和安装MySQL: - 进入解压后的MySQL源码目录: ``` cd mysql-<version> ``` - 使用下面的命令配置编译选项: ``` cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITH_SSL=yes ``` - 执行下面的命令编译并安装MySQL: ``` make && sudo make install ``` 6. 创建MySQL用户和组: - 在终端中,执行以下命令创建MySQL用户和组: ``` sudo groupadd mysql sudo useradd -r -g mysql -s /bin/false mysql ``` 7. 初始化MySQL数据目录: - 在终端中,进入MySQL安装目录: ``` cd /usr/local/mysql ``` - 执行以下命令初始化MySQL数据目录: ``` sudo scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data ``` 8. 配置MySQL: - 在终端中,执行以下命令编辑MySQL配置文件: ``` sudo vi /etc/my.cnf ``` - 将以下内容添加到文件中: ``` [mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data ``` - 保存并退出配置文件。 9. 启动MySQL服务: - 在终端中,执行以下命令启动MySQL服务: ``` sudo /usr/local/mysql/support-files/mysql.server start ``` 10. 设置root密码: - 在终端中,执行以下命令登录MySQL服务器: ``` /usr/local/mysql/bin/mysql -u root ``` - 在MySQL提示符下,执行以下命令设置root密码: ``` ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_password'; ``` (将"your_password"替换为您想要设置的密码) - 退出MySQL提示符: ``` quit ``` 现在,您已经成功在CentOS 7上通过源码安装MySQL。您可以使用以下命令启动和停止MySQL服务: ``` sudo /usr/local/mysql/support-files/mysql.server start sudo /usr/local/mysql/support-files/mysql.server stop ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值