yum install mysql 经常会出现各种问题,编译安装Mysql也会出现很多,什么依赖库不存在,然后再去安装这些依赖库的问题,很是头疼.所以直接采用官方编译好的二进制包安装.
已知的不兼容的平台 树莓派P2
直接下载 https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
更多版本的下载 到 https://dev.mysql.com/downloads/mysql/
注意选择操作系统
下载可能会很慢,建议使用迅雷下载
(1)首先卸载mariadb,不然后面会和安装mysql需要的库冲突:
[root@localhost ~]# rpm -qa | grep mariadb mariadb-libs-5.5.56-2.el7.x86_64 [root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
(2) 添加用户
[root@localhost home]# groupadd mysql [root@localhost home]# useradd -r -g mysql -s /bin/false mysql
(3) 解压安装包
[root@localhost home]# tar -xzvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz [root@localhost home]# mv mysql-5.7.29-linux-glibc2.12-x86_64 /usr/local/ [root@localhost home]# cd /usr/local/ [root@localhost local]# mv mysql-5.7.29-linux-glibc2.12-x86_64/ mysql
(4) 初始化安装
cd /usr/local/mysql
[root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql
其中--basedir mysql基础目录(就是你二进制包目录) --datadir mysql数据存放目录(如果不指定就在二进制包目录的data 文件夹下,会自动创建),并创建了root用户的临时密码
[root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql 2020-04-17T05:58:26.644493Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2020-04-17T05:58:26.836346Z 0 [Warning] InnoDB: New log files created, LSN=45790 2020-04-17T05:58:26.928129Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2020-04-17T05:58:26.985241Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 74a48286-8070-11ea-a5e9-000c29c14966. 2020-04-17T05:58:26.986019Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened. 2020-04-17T05:58:27.328055Z 0 [Warning] CA certificate ca.pem is self signed. 2020-04-17T05:58:27.574192Z 1 [Note] A temporary password is generated for root@localhost: lareha)1j*2E [root@localhost mysql]#
注意最后一行,是mysql 给你生成的临时密码
开启ssl连接:
[root@localhost mysql]# bin/mysql_ssl_rsa_setup
起飞
[root@localhost mysql]# bin/mysqld_safe --user=mysql &
加入环境变量
[root@localhost /]# vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
[root@localhost /]# source /etc/profile
加入开机自启动
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql.server [root@localhost mysql]# chkconfig --add mysql.server
如果你的安装不在/usr/local/mysql 则需要这个mysql.server 文件
把里面的 /usr/local/mysql 全部替换成你的安装目录即可
登录
[root@localhost mysql]# mysql -uroot -p
注意记住刚才生成的密码,复制的时候不要加上空格
然后登录成功修改密码
mysql> set password for root@localhost = password(‘123123‘);
不要把密码设置这么简单
重启
[root@localhost ~]# lsof -i:3306 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 1179 mysql 28u IPv6 21193 0t0 TCP *:mysql (LISTEN)
大功告成
!!!