您的位置:首页 > 数据库 > MySQL

MySQL 5.7.15 安装(二进制安装模式)

2016-11-15 12:45 309 查看
MySQL 5.7.1x 比以往版本安装有些不一样,第一次安装5.7,安装过程遇到挺多小问题,现简单总结安装过程如下。

这次安装的是 mysql-5.7.16-linux-glibc2.5-i686.tar.gz,更多下载参考MySQL
安装(二进制安装模式),

安装相关包(依赖包自动安装):

yum -y install gcc glibc libaio libstdc++ libstdc libncurses ld-linux


配置文件:

shell> vi /etc/my.cnf

[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
user=mysql
port = 3306
server_id = 1
socket=/tmp/mysql.sock
basedir =/usr/local/mysql
datadir =/usr/local/mysql/data
pid-file=/usr/local/mysql/data/mysqld.pid
log-error=/usr/local/mysql/log/mysql-error.log
# 官网安装参考

http://dev.mysql.com/doc/refman/5.7/en/binary-installation.html

shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> mkdir mysql-files
shell> chmod 750 mysql-files
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql# MySQL 5.7.0 to 5.7.4
shell> bin/mysql_install_db --user=mysql    # MySQL 5.7.5
shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up
shell> bin/mysql_ssl_rsa_setup              # MySQL 5.7.6 and up
shell> chown -R root .
shell> chown -R mysql data mysql-files
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server


安装:

shell> tar -xvf mysql-5.7.16-linux-glibc2.5-i686.tar.gz
shell> mv mysql-5.7.16-linux-glibc2.5-i686 /usr/local/
shell> cd /usr/local/
shell> ln -s mysql-5.7.16-linux-glibc2.5-i686 mysql
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd mysql
shell> chown -R mysql:mysql .
shell> bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --explicit_defaults_for_timestamp


[root@centos224 mysql]# bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --explicit_defaults_for_timestamp
2016-11-22T14:14:53.799055Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-11-22T14:14:54.208059Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-11-22T14:14:54.371661Z 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: 0a41777d-b0be-11e6-b802-000c29b81537.
2016-11-22T14:14:54.405756Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-11-22T14:14:54.417890Z 1 [Note] A temporary password is generated for root@localhost: AbC#c*hiy0bl
[root@centos224 mysql]#

注意:数据库账号 root@localhost 的密码自动随机生成 AbC#c*hiy0bl  (如上所示),登录后要求必须先改密码。(可查看日志信息)

配置服务:

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chkconfig mysqld on

# service mysqld start
# service mysqld restart
# service mysqld stop

添加环境变量:

# vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin

# source /etc/profile

访问数据库:

# mysql -u root -p
Enter password:AbC#c*hiy0bl


如果访问忘记密码,错误如下:

# mysql
# mysqladmin -u root password "mysql"
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
解决:

# service mysqld stop
# cd /usr/local/mysql/bin
# mysqld_safe --skip-grant-tables &

--(再打开另一命令行窗口,直接访问数据库并设置密码)
# source /etc/profile
# mysql -u root
mysql>
mysql> use mysql;
mysql> select Host,User from user;
mysql> update user set authentication_string=password("mysql") where user="root" and Host = 'localhost';
mysql> flush privileges;

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql';
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: