目录
1.1 机器准备
#一台虚拟机
hostname:myhost
ip:ip_address
1.2 系统环境
[root@myhost ~]
CentOS release 6.5 (Final)
[root@myhost ~]
[root@myhost ~]
[root@myhost ~]
Disabled
[root@myhost ~]
1.3 软件安装约定
安装包存放目录:/home/tools
Mysql安装目录:/usr/local/mysql
数据库保存位置:/usr/local/mysql/data
日志保存位置:/usr/local/mysql/log
1.4 下载安装包
[root@myhost ~]
[root@myhost tools]
[root@myhost tools]
total 835560
-rw-r--r--. 1 root root 639864682 May 25 2016 mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
[root@myhost tools]
1.5 解压安装包
[root@myhost tools]
[root@myhost tools]
total 8355
drwxr-xr-x. 9 7161 wheel 4M May 25 2016 mysql-5.7.13-linux-glibc2.5-x86_64
-rw-r--r--. 1 root root 611M May 25 2016 mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
[root@myhost tools]
1.6 安装
[root@myhost tools]
1.7 创建管理数据库的用户和组
[root@myhost tools]
[root@myhost tools]
uid=503(mysql) gid=503(mysql) groups=503(mysql)
1.8 创建数据库存放目录以及日志目录
[root@myhost tools]
[root@myhost tools]
[root@myhost tools]
1.9 修改整个mysql目录的权限
[root@myhost tools]
2.0 配置数据库环境变量
[root@myhost tools]
[root@myhost tools]
[root@myhost tools]
2.1 初始化数据库并记录下数据库的临时密码
[ ] -- -- -- --
[root@myhost tools]
2.2 修改mysql的主配置文件以及启动文件
[root@myhost support-files]
cp: overwrite `/etc/my.cnf'? y
[root@myhost support-files]
[root@myhost support-files]
[client]
port = 4110
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
port = 4110
character-set-server = utf8
collation-server = utf8_general_ci
skip-external-locking
skip-name-resolve
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
tmpdir = /usr/local/mysql/data/temp #需要在数据库初始化之后自行创建并修改权限,否则会报错。
socket = /usr/local/mysql/mysql.sock
open_files_limit = 10240
back_log = 600
max_connections=2000
max_connect_errors = 6000
wait_timeout=605800
max_allowed_packet = 32M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size = 300
query_cache_type = 1
query_cache_size = 256M
query_cache_limit = 2M
query_cache_min_res_unit = 16k
tmp_table_size = 256M
max_heap_table_size = 256M
key_buffer_size = 256M
read_buffer_size = 8M
read_rnd_buffer_size = 64M
bulk_insert_buffer_size = 64M
lower_case_table_names=1
lower_case_table_names=1
default-storage-engine = INNODB
innodb_buffer_pool_size = 10G
innodb_log_buffer_size = 32M
innodb_log_file_size = 128M
innodb_flush_method = O_DIRECT
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqldump]
quick
max_allowed_packet = 32M
[mysqld_safe]
log-error=/usr/local/mysql/log/mysqld_4110.err
pid-file=/usr/local/mysql/run/mysqld.pid
2.3 启动mysql
[root@myhost support-files]
[root@myhost support-files]
[root@myhost support-files]
[root@myhost ~]
2.4 登录mysql数据库
[root@myhost support-files]
Enter password: 7/Hf)6W9fuer
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.13
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>
2.5 为root用户设置新密码
mysql> set password=password('新密码');
mysql> grant all privileges on *.* to root@'%' identified by '新密码';
mysql> flush privileges;
mysql> update mysql.user set authentication_string=password('新密码') where User='root' and Host='localhost'; #另外一种修改root用户密码的方法
mysql> exit;
2.6 用新密码重新登录数据库
[root@myhost support-files]
Enter password: 新密码
2.7 创建一个新用户并授权
mysql> grant all privileges on *.* to other@'%' identified by 'other123456';
mysql> flush privileges;
mysql> use mysql;
mysql> select host,user from mysql.user;
2.8 在其他主机远程连接数据库
[root@client ~]
Enter password: other123456
2.9 将mysql服务加入开机自启动
[root@myhost ~]
[root@myhost ~]
[root@myhost ~]
3.0 重启mysql服务
[root@myhost ~]
[root@myhost ~]
[root@myhost ~]
[root@myhost ~]
[root@myhost ~]