linux centos7.3 安装mysql5.7.14

来源:互联网 发布:桌面整理软件下载 编辑:程序博客网 时间:2024/06/18 07:59

linux centos7.3 安装mysql5.7.14

1 检查是否已经安装过mysql

  • 安装过则卸载mysql

[root@iZ23ugo7jxaZ opt]# rpm -qa | grep mysql

mysql-libs-5.1.73-3.el6_5.x86_64

[root@iZ23ugo7jxaZ opt]# rpm -e mysql-libs-5.1.73-3.el6_5.x86_64 --nodeps

  • 未安装过跳过

2 检查是否建立mysql用户组和用户

  • 未建立mysql用户组和用户,则创建

[root@iZ23ugo7jxaZ opt]# rpm -qa | grep mysql

[root@iZ23ugo7jxaZ opt]#  cat /etc/group | grep mysql

[root@iZ23ugo7jxaZ opt]# cat /etc/passwd | grep mysql
[root@iZ23ugo7jxaZ opt]# groupadd mysql
[root@iZ23ugo7jxaZ opt]#  cat /etc/group | grep mysql
mysql:x:500:
[root@iZ23ugo7jxaZ opt]# useradd -r -g mysql mysql

  • 创建过则跳过

3 安装包解压到/usr/local,并重名为mysql3306

4 配置my.cnf

[root@iZ23ugo7jxaZ mysql3306]# cd /usr/local/mysql3306

[root@iZ23ugo7jxaZ mysql3306]# cp support-files/my-default.cnf ./my.cnf

[root@iZ23ugo7jxaZ mysql3306]# vi my.cnf

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the

# *** default location during install, and will be replaced if you

# *** upgrade to a newer version of MySQL.

[client]

port=3306

[mysql]

default-character-set=utf8

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M


# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

#  log_bin=mysql-bin


# These are commonly set, remove the # and set as required.

 basedir = /usr/local/mysql3306

 datadir = /usr/local/mysql3306/data

 port = 3306

 server_id = 1

 socket =/tmp/mysqld3306.sock

5 改变安装文件的用户组为mysql

[root@iZ23ugo7jxaZ mysql3306]# cd /usr/local

[root@iZ23ugo7jxaZ local]# ls

aegis  bin  etc  games  include  lib  lib64  libexec  mysql3306  sbin  share  src

[root@iZ23ugo7jxaZ local]# chown -Rf mysql:mysql mysql3306

6 安装mysql

[root@iZ23ugo7jxaZ local]# cd mysql3306

[root@iZ23ugo7jxaZ mysql3306]# ls

bin  COPYING  docs  include  lib  man  my.cnf  README  share  support-files

[root@iZ23ugo7jxaZ mysql3306]# bin/mysqld --defaults-file=/usr/local/mysql3306/my.cnf --initialize-insecure --user=mysql

如果碰到以下错误:

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

解决问题

yum install libaio*

7 设置系统自动启动mysql

[root@iZ23ugo7jxaZ mysql3306]# cd support-files/
[root@iZ23ugo7jxaZ support-files]# ls
magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@iZ23ugo7jxaZ support-files]# cp mysql.server /etc/init.d/mysqld3306

[root@iZ23ugo7jxaZ support-files]# vi /etc/init.d/mysqld3306

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir=/usr/local/mysql3306
datadir=/usr/local/mysql3306/data

删除centos系统自身的my.cnf

[root@iZ23ugo7jxaZ mysql3306]# cd /etc/

[root@iZ23ugo7jxaZ etc]# rm -rf my.cnf

[root@iZ23ugo7jxaZ etc]# /etc/init.d/mysqld3306 start
Starting MySQL.[  OK  

[root@iZ23ugo7jxaZ etc]# chkconfig --level 35 mysqld3306 on

8 登录mysql,修改root访问权限

[root@iZ23ugo7jxaZ mysql3306]# bin/mysql -S /tmp/mysqld3306.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.14 MySQL Community Server (GPL)


Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)


mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

9 修改root密码

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A


Database changed

mysql> update user set authentication_string=PASSWORD("123456")where user="root";
Query OK, 2 rows affected, 1 warning (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 1


mysql> flush privileges;

mysql> exit