MySQL二进制包安装-CentOS7/Ubuntu16

0. 软件版本及运行环境:
MySQL5.7.19(64位) + CentOS7/Ubuntu16
1、删除系统旧rpm包
Centos

[root@localhost ~]# rpm -qa | grep -i mysql
mysql-libs-5.1.73-8.el6_8.x86_64
[root@localhost ~]# yum -y remove mysql-libs-5.1* 
[root@localhost ~]# whereis mysql
mysql:

Ubuntu

[root@localhost ~]# rpm -qa | grep -i mysql 
mysql-5.0.77-4.el5_6.6
[root@localhost ~]#  rpm -e –allmatches mysql-5.0.77-4.el5_6.6 

2、官网下载二进制包
[root@localhost ~]# mkdir -p /tools
[root@localhost tools]# cd /tools
[root@localhost tools]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz

3、创建mysql 运行帐号
[root@localhost tools]# groupadd mysql
[root@localhost tools]# useradd -g mysql -d /usr/local/mysql -s /sbin/nologin -M mysql
[root@localhost tools]# id mysql
uid=501(mysql) gid=501(mysql) groups=501(mysql)
[root@localhost tools]#

4、软件安装
[root@localhost tools]# mkdir /opt/mysql
[root@localhost tools]# cd /opt/mysql
[root@localhost mysql]# tar zxvf /tools/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
[root@localhost mysql]# cd /usr/local/
[root@localhost local]# ln -s /opt/mysql/mysql-5.7.19-linux-glibc2.12-x86_64 mysql
[root@localhost local]# chown -R mysql:mysql mysql/

5、运行环境配置
配置文件:/etc/my.cnf

[mysqld]
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql/mysql3306/data
log_error=/data/mysql/mysql3306/logs/error.log
expire_logs_days = 30
log_bin=/data/mysql/mysql3306/binlog/binlog.log
relay_log=/data/mysql/mysql3306/binlog/relay.log
server_id=1

[root@localhost local]# mkdir /data/mysql/mysql3306/{data,logs,tmp,binlog} -p

[root@localhost local]# chown -R mysql:mysql /data/mysql/

6、初始化
[root@localhost local]# cd /usr/local/mysql
[root@localhost mysql]# ./bin/mysqld --defaults-file=/etc/my.cnf --initialize

**参数释义:**
--initialize会生成一个随机密码(error.log);--initialize-insecure不会生成密码
--datadir目录下不能有数据文件

[root@localhost mysql]# find / -name mysql_install_db
[root@localhost mysql]# cat /data/mysql/mysql3306/data/error.log |grep password

7、数据库实例启动
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql
[root@localhost mysql]# /etc/init.d/mysql start
[root@localhost mysql]# /etc/init.d/mysql status # 检查数据库运行状态

8、设置mysql 登录密码
去掉my.cnf中–skip-grant-tables前的注释,重启数据库服务(如果能知道第6步生成的密码就不需这样折腾)
[root@localhost mysql]# ./bin/mysql -uroot
[root@localhost mysql]# ./bin/mysql -S /tmp/mysql3306.sock
进入数据库,尝试使用alter user修改密码
root@localhost [(none)]> alter user root@localhost identified by ‘Mysql@@)@)’; #@)@) 是 shift 加2020
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

root@localhost [(none)]> use mysql;
root@localhost [mysql]> update user set authentication_string=password(‘Mysql@@)@)’) where User=‘root’;
Query OK, 1 row affected, 1 warning (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 1
退出,注释my.cnf中–skip-grant-tables,重启数据库服务,再重新进入
root@localhost [mysql]> exit
[root@localhost mysql]# ./bin/mysql -uroot -p
Enter password: 键入新密码
root@localhost [(none)]> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
出现这个错误的原因是user表中的password_expired字段取值为Y,密码过期需修改
root@localhost [(none)]> alter user ‘root’@‘localhost’ identified by ‘Mysql@@)@)’;
root@localhost [(none)]> exit

9、配置mysql全局运行环境
[root@localhost mysql]# echo “export PATH=$PATH:/usr/local/mysql/bin” >> /etc/profile
[root@localhost mysql]# source /etc/profile
[root@localhost mysql]# echo $PATH

[root@localhost mysql]# mysql -uroot -p
Enter password: 键入正确密码

10、关闭mysql
[root@localhost mysql]# /etc/init.d/mysql stop

  1. 问题积累
    11.1 ./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

centos

root@bigdata-159:/usr/local/mysql# ./bin/mysqld -- defaults-file=/etc/my.cnf --initialize --user=mysql

 
解决方法:

[[email protected] data]# yum install -y libaio  

欢迎留言指正!

猜你喜欢

转载自blog.csdn.net/qq_31024251/article/details/108253249
今日推荐