本博客是采用yum源的方式安装,非常的方便和快捷。(redhat 与centos7 等操作系统都可以采用此方法,步骤大体一致)
mysql官网地址: https://dev.mysql.com
开始安装:
1.清理环境,查看有没有之前安装过的mysql记录,清理掉
[root@long2 ~]# rpm -qa | grep mysql
mysql-libs-5.1.52-1.el6_0.1.x86_64
[root@long2 ~]# yum remove mysql-xxx-xxx-
2.清理掉之前的mysql相关配置,清理掉
[root@long2 ~]# find / -name mysql
/var/spool/mail/mysql
/var/lock/subsys/mysql
/usr/share/mysql
/usr/local/mysql-5.6.33/data/mysql
/usr/local/mysql-5.6.33/data/mysql/mysql
/usr/local/mysql-5.6.33/include/mysql
/usr/local/mysql-5.6.33/bin/mysql
/usr/lib64/mysql
/home/long/test/php-5.6.32/travis/ext/mysql
/home/long/test/php-5.6.32/ext/mysql
/home/mysql[root@long2 ~]# rpm -pa | grep mariadb全部清理掉
[root@long2 ~]# rm -rf /var/lock/subsys/mysql /usr/share/mysql /usr/local/mysql-5.6.33 /usr/lib64/mysql /home/long/test /home/mysql
3.确认3306端口没有被占用
[root@long2 ~]# ps -ef | grep mysql
4.找到对应的mysql yum源
https://dev.mysql.com/downloads/repo/yum/
根据自己的操作系统选择对应的yum源的rpm包下载,我们这里选择的是centos6的
[root@long2 ~]# wget https://repo.mysql.com//mysql80-community-release-el6-1.noarch.rpm
[root@long2 ~]# rpm -ivh mysql80-community-release-el6-1.noarch.rpm
warning: mysql80-community-release-el6-1.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]1:mysql80-community-relea########################################### [100%]
5.使用yum安装mysql
[root@long2 ~]# yum clean all
[root@long2 ~]# yum makecache
5.1
[root@long2 ~]# yum repolist all | grep mysql
如果想安装mysql其他的版本则可以通过修改/etc/yum.repos.d/mysql-community.repo 这个配置文件 将对应的mysql版本的enabled 值改为1或者通过下面命令修改
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
开始安装:
[root@long2 ~]# yum install mysql-community-server
6.启动
[root@long2 ~]# /etc/init.d/mysqld start
启动时候mysql会输出初始密码,mysql在安装后会创建一个root@locahost账户,并且把初始的密码放到了/var/log/mysqld.log文件中
或者查看日志文件:/var/log/mysqld.log
7.登录
[root@long2 ~]# mysql -u root -p #后面输入上面的密码
登录成功
8.注意第一次登陆上去后会强制要求修改密码,否则会报错。
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
修改密码:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'QWER1234,,!!&==13a5sdfa';
Query OK, 0 rows affected (0.02 sec)
注意: 如果密码太简单也会报错。
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'QWER1234,,!!';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements