首页 > 开发 > MySQL > 正文

mysql 5.7.10 二进制安装

2016-06-01 20:07:33  来源:慕课网
题记:最近刚开始学习mysql,发现自己对于linux 下面mysql的安装了解的太少了,呃呃呃   于是我就先了解了mysql的三种安装方式:
  1.源码安装,过程感觉比较繁琐,时间长
  2.二进制安装 ,相对简单
  3.rpm安装 简单 (参考下面文章 http://blog.itpub.net/8183550/viewspace-680749/
最后我选择了二进制安装的方式,我的操作系统centos6.4 64位
正文:   1、添加MySQL的操作系统用户
  useradd mysql
  2、下载mysql安装包:
  wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.10-linux-glibc2.5-x86_64.tar (我选择的是通用版本的mysql,会比较大,大概五六百兆,该压缩包包括源码和测试数据库)
  tar -zxvf mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
cd /usr/local/
ls
mv mysql-5.7.10-linux-glibc2.5-x86_64/ mysql
  3、修改权限
  cd /usr/local/
chown mysql.mysql mysql -R
  4、建立库文件目录(根据需要自己定义)
  mkdir /mysqldata/3310
cd 3310
mkdir data (建立数据库目录)
touch my.cnf
cd /
chown -R mysql:mysql /mysqldata (权限定义)
  4.配置my.cnf
  [mysqld]
server_id = 72(自己设置唯一值)
user = mysql
port = 3310
datadir = /mysqldata/3310/data
basedir = /usr/local/mysql
log-bin = /mysqldata/3310/binlog
socket = /mysqldata/3310/mysql.sock
pid-file = /mysqldata/3310/mysql.pid
log-error = /mysqldata/3310/mysql_error.log
relay-log = /mysqldata/3310/relaylog
relay-log-index = /mysqldata/3310/relaylog.index
default-storage-engine = Innodb
[慢查询]
long_query_time = 1
slow-query-log = on
slow_query_log_file = /mysqldata/3310/mysql_slow.log
记录更多的日志
log_slow_admin_statements
character-set-server = utf8
open_files_limit = 10240
参考:短时间内最大连接
back_log = 1024
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 1G
expire_logs_days = 2
  5、库初始化
  /usr/local/mysql/bin/mysqld --initialize --datadir=/data/mysqldata/3310/data --basedir=/usr/local/mysql --user=mysql # MySQL 5.7.6 and up
  查看部分结果
2016-01-15T15:06:12.986783Z 1 [Note] A temporary password is generated for root@localhost: 02dqBq_%J/ni
最后是用户root@localhost的临时密码,待会儿会用到。
  6、启库
推荐mysqld_safe启动mysql
  /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/3310/my.cnf &
  7、此时登录MySQL
  /usr/local/mysql/bin/mysql -uroot --socket=/data/mysqldata/3310/mysql.sock -p02dqBq_%J/ni #输入初始化时的密码
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. #修改root密码后才能使用
mysql> set password for root@localhost = password('123456');
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
  mysql> select user,host from mysql.user;
+-----------+-----------+
| user | host |
+-----------+-----------+
| mysql.sys | localhost |
| root | localhost |
+-----------+-----------+
2 rows in set (0.00 sec)
  5.7跟5.6区别:
初始化库的命令换了 root@localhost有了初始化密码,必须先改密码后,才能使用。 不能用grant新建用户了
mysql> grant all on . to zwz;
ERROR 1133 (42000): Can't find any matching row in the user table   mysql> create user zwz;
Query OK, 0 rows affected (0.01 sec)
  mysql> grant all on . to zwz;
Query OK, 0 rows affected (0.01 sec)
  (ps:写的不对的地方,欢迎拍砖:))
  部分命令
  /usr/local/mysql/bin/mysqladmin -S /mysqldata/3310/mysql.sock -uroot -p shutdown
  /usr/local/mysql/bin/mysql -S /mysqldata/3310/mysql.sock -uroot -p
  /usr/local/mysql/bin/mysqld_safe --defaults-extra-file=/mysqldata/3310/my.cnf &