centos rpm方式安装mysql

17 篇文章 2 订阅
11 篇文章 0 订阅

卸载原有的mysql

[root@dev22 mysql]# rpm -qa | grep -i mysql
MySQL-devel-5.6.38-1.el6.x86_64
MySQL-client-5.6.38-1.el6.x86_64
MySQL-server-5.6.38-1.el6.x86_64

#卸载
[root@dev22 mysql]# rpm -e --nodeps MySQL-server-5.6.38-1.el6.x86_64 MySQL-client-5.6.38-1.el6.x86_64 MySQL-devel-5.6.38-1.el6.x86_64

#删除文件夹和文件
rm -rf /var/lib/mysql/ /usr/lib64/mysql/ /root/.mysql_secret /usr/my.cnf /etc/my.cnf 

下载

https://dev.mysql.com/downloads/mysql/5.6.html#downloads

安装

[root@localhost mysql]# tar -xvf MySQL-5.6.38-1.el6.x86_64.rpm-bundle.tar


# 安装服务端
[root@dev22 mysql]# rpm -ivh MySQL-server-5.6.38-1.el6.x86_64.rpm 
warning: MySQL-server-5.6.38-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]
2017-11-14 13:34:49 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-14 13:34:49 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-11-14 13:34:49 0 [Note] /usr/sbin/mysqld (mysqld 5.6.38) starting as process 9985 ...
2017-11-14 13:34:49 9985 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-11-14 13:34:49 9985 [Note] InnoDB: The InnoDB memory heap is disabled
2017-11-14 13:34:49 9985 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-11-14 13:34:49 9985 [Note] InnoDB: Memory barrier is not used
2017-11-14 13:34:49 9985 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-11-14 13:34:49 9985 [Note] InnoDB: Using Linux native AIO
2017-11-14 13:34:49 9985 [Note] InnoDB: Using CPU crc32 instructions
2017-11-14 13:34:49 9985 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-11-14 13:34:49 9985 [Note] InnoDB: Completed initialization of buffer pool
2017-11-14 13:34:49 9985 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2017-11-14 13:34:49 9985 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2017-11-14 13:34:49 9985 [Note] InnoDB: Database physically writes the file full: wait...
2017-11-14 13:34:49 9985 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2017-11-14 13:34:49 9985 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2017-11-14 13:34:50 9985 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2017-11-14 13:34:50 9985 [Warning] InnoDB: New log files created, LSN=45781
2017-11-14 13:34:50 9985 [Note] InnoDB: Doublewrite buffer not found: creating new
2017-11-14 13:34:50 9985 [Note] InnoDB: Doublewrite buffer created
2017-11-14 13:34:50 9985 [Note] InnoDB: 128 rollback segment(s) are active.
2017-11-14 13:34:50 9985 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-11-14 13:34:50 9985 [Note] InnoDB: Foreign key constraint system tables created
2017-11-14 13:34:50 9985 [Note] InnoDB: Creating tablespace and datafile system tables.
2017-11-14 13:34:50 9985 [Note] InnoDB: Tablespace and datafile system tables created.
2017-11-14 13:34:50 9985 [Note] InnoDB: Waiting for purge to start
2017-11-14 13:34:50 9985 [Note] InnoDB: 5.6.38 started; log sequence number 0
A random root password has been set. You will find it in '/root/.mysql_secret'.
2017-11-14 13:34:55 9985 [Note] Binlog end
2017-11-14 13:34:55 9985 [Note] InnoDB: FTS optimize thread exiting.
2017-11-14 13:34:55 9985 [Note] InnoDB: Starting shutdown...
2017-11-14 13:34:57 9985 [Note] InnoDB: Shutdown completed; log sequence number 1625977


2017-11-14 13:34:57 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-14 13:34:57 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-11-14 13:34:57 0 [Note] /usr/sbin/mysqld (mysqld 5.6.38) starting as process 10007 ...
2017-11-14 13:34:57 10007 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-11-14 13:34:57 10007 [Note] InnoDB: The InnoDB memory heap is disabled
2017-11-14 13:34:57 10007 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-11-14 13:34:57 10007 [Note] InnoDB: Memory barrier is not used
2017-11-14 13:34:57 10007 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-11-14 13:34:57 10007 [Note] InnoDB: Using Linux native AIO
2017-11-14 13:34:57 10007 [Note] InnoDB: Using CPU crc32 instructions
2017-11-14 13:34:57 10007 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-11-14 13:34:57 10007 [Note] InnoDB: Completed initialization of buffer pool
2017-11-14 13:34:57 10007 [Note] InnoDB: Highest supported file format is Barracuda.
2017-11-14 13:34:57 10007 [Note] InnoDB: 128 rollback segment(s) are active.
2017-11-14 13:34:57 10007 [Note] InnoDB: Waiting for purge to start
2017-11-14 13:34:57 10007 [Note] InnoDB: 5.6.38 started; log sequence number 1625977
2017-11-14 13:34:57 10007 [Note] Binlog end
2017-11-14 13:34:57 10007 [Note] InnoDB: FTS optimize thread exiting.
2017-11-14 13:34:57 10007 [Note] InnoDB: Starting shutdown...
2017-11-14 13:34:59 10007 [Note] InnoDB: Shutdown completed; log sequence number 1625987



#生成的root密码临时文件
A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.

Also, the account for the anonymous user has been removed.

In addition, you can run:

  /usr/bin/mysql_secure_installation

which will also give you the option of removing the test database.
This is strongly recommended for production servers.

See the manual for more instructions.

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

# 安装客户端
[root@dev22 mysql]# rpm -ivh MySQL-client-5.6.38-1.el6.x86_64.rpm 
warning: MySQL-client-5.6.38-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]
#
[root@dev22 mysql]# rpm -ivh MySQL-devel-5.6.38-1.el6.x86_64.rpm 
warning: MySQL-devel-5.6.38-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:MySQL-devel            ########################################### [100%]

自定义目录

如果不自定义datadir可以绕过这一步
#创建目录
[root@dev22 mysql]# mkdir -p  /data/mysql/data /data/mysql/logs /data/mysql/tmp
# 授权
[root@dev22 mysql]# chown -R mysql.mysql /data/mysql/

# 修改/etc/init.d/mysql 和/usr/share/mysql/mysql.server  中datadir的路径为 /data/mysql/data
[root@dev22 mysql]# vim /etc/init.d/mysql 
[root@dev22 mysql]# vim /usr/share/mysql/mysql.server 

修改配置文件

# The following options will be passed to all MySQL clients
[client]
#客户端默认连接字集集,若编译安装时已指定则不用填写
#character-set-server = utf8  
#客户端连接通信端口
port = 3306    
#客户端通信的用户密码端口等信息保存文件
socket = /data/mysql/tmp/mysql.sock   
default-character-set=utf8

# The MySQL server
[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%.
#配置mysql的内存大小,一般数据库服务器的80%
innodb_buffer_pool_size = 1g
#mysql服务端监听端口
port  = 3306     
# 指定服务器id
server_id = 22
#mysql数据库存放目录
datadir = /data/mysql/data 
#socket = /data/mysql/tmp/mysql.sock       
#服务端pid进程文件,若丢失则重启Mysql重新生成,若重启失败,
#则可能由于mysqld进程未杀死,用pkill mysql后则能重启成功Mysql
pid-file =/data/mysql/mysqld.pid
#指定错误日志目录
log-error=/data/mysql/logs

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M  
explicit_defaults_for_timestamp=true
lower_case_table_names=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
performance_schema_max_table_instances=400
table_definition_cache=400
table_open_cache=256
max_allowed_packet = 32M
# 设置默认引擎
default-storage-engine=INNODB
#设置默认字符
character-set-server=utf8 
collation-server=utf8_general_ci
#设置最大链接数
max_connections=500

初始化数据库

[root@dev22 mysql]# /usr/bin/mysql_install_db --user=mysql --datadir=/data/mysql/data
Installing MySQL system tables...2017-11-14 15:43:46 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-14 15:43:46 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-11-14 15:43:46 0 [Note] /usr/sbin/mysqld (mysqld 5.6.38) starting as process 10475 ...
2017-11-14 15:43:46 10475 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-11-14 15:43:46 10475 [Note] InnoDB: The InnoDB memory heap is disabled
2017-11-14 15:43:46 10475 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-11-14 15:43:46 10475 [Note] InnoDB: Memory barrier is not used
2017-11-14 15:43:46 10475 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-11-14 15:43:46 10475 [Note] InnoDB: Using Linux native AIO
2017-11-14 15:43:46 10475 [Note] InnoDB: Using CPU crc32 instructions
2017-11-14 15:43:46 10475 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-11-14 15:43:46 10475 [Note] InnoDB: Completed initialization of buffer pool
2017-11-14 15:43:46 10475 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2017-11-14 15:43:46 10475 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2017-11-14 15:43:46 10475 [Note] InnoDB: Database physically writes the file full: wait...
2017-11-14 15:43:46 10475 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2017-11-14 15:43:46 10475 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2017-11-14 15:43:47 10475 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2017-11-14 15:43:47 10475 [Warning] InnoDB: New log files created, LSN=45781
2017-11-14 15:43:47 10475 [Note] InnoDB: Doublewrite buffer not found: creating new
2017-11-14 15:43:47 10475 [Note] InnoDB: Doublewrite buffer created
2017-11-14 15:43:47 10475 [Note] InnoDB: 128 rollback segment(s) are active.
2017-11-14 15:43:47 10475 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-11-14 15:43:47 10475 [Note] InnoDB: Foreign key constraint system tables created
2017-11-14 15:43:47 10475 [Note] InnoDB: Creating tablespace and datafile system tables.
2017-11-14 15:43:47 10475 [Note] InnoDB: Tablespace and datafile system tables created.
2017-11-14 15:43:47 10475 [Note] InnoDB: Waiting for purge to start
2017-11-14 15:43:47 10475 [Note] InnoDB: 5.6.38 started; log sequence number 0
2017-11-14 15:43:52 10475 [Note] Binlog end
2017-11-14 15:43:52 10475 [Note] InnoDB: FTS optimize thread exiting.
2017-11-14 15:43:52 10475 [Note] InnoDB: Starting shutdown...
2017-11-14 15:43:54 10475 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK

Filling help tables...2017-11-14 15:43:54 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-14 15:43:54 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-11-14 15:43:54 0 [Note] /usr/sbin/mysqld (mysqld 5.6.38) starting as process 10497 ...
2017-11-14 15:43:54 10497 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-11-14 15:43:54 10497 [Note] InnoDB: The InnoDB memory heap is disabled
2017-11-14 15:43:54 10497 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-11-14 15:43:54 10497 [Note] InnoDB: Memory barrier is not used
2017-11-14 15:43:54 10497 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-11-14 15:43:54 10497 [Note] InnoDB: Using Linux native AIO
2017-11-14 15:43:54 10497 [Note] InnoDB: Using CPU crc32 instructions
2017-11-14 15:43:54 10497 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-11-14 15:43:54 10497 [Note] InnoDB: Completed initialization of buffer pool
2017-11-14 15:43:54 10497 [Note] InnoDB: Highest supported file format is Barracuda.
2017-11-14 15:43:54 10497 [Note] InnoDB: 128 rollback segment(s) are active.
2017-11-14 15:43:54 10497 [Note] InnoDB: Waiting for purge to start
2017-11-14 15:43:54 10497 [Note] InnoDB: 5.6.38 started; log sequence number 1625977
2017-11-14 15:43:54 10497 [Note] Binlog end
2017-11-14 15:43:54 10497 [Note] InnoDB: FTS optimize thread exiting.
2017-11-14 15:43:54 10497 [Note] InnoDB: Starting shutdown...
2017-11-14 15:43:56 10497 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  /usr/bin/mysqladmin -u root password 'new-password'
  /usr/bin/mysqladmin -u root -h dev22 password 'new-password'

Alternatively you can run:

  /usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

WARNING: Found existing config file /usr/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /usr/my-new.cnf,
please compare it with your file and take the changes you need.

启动数据库服务

[root@dev22 mysql]# service mysql start
Starting MySQL.171114 15:45:51 mysqld_safe error: log-error set to '/data/mysql/logs.err', however file don't exists. Create writable for user 'mysql'.
The server quit without updating PID file (/data/mysql/mysq[失败]).
出现以上情况建议关闭SELinux
[root@dev22 mysql]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#SELINUX=enforcing  #注释掉
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
#SELINUXTYPE=targeted  #注释掉
SELINUX=disabled #增加

source /etc/selinux/config


root@dev22 mysql]# service mysql start
Starting MySQL.171114 16:39:03 mysqld_safe error: log-error set to '/data/mysql/logs.err', however file don't exists. Create writable for user 'mysql'.
The server quit without updating PID file (/data/mysql/mysq[失败]).
# 创建logs.err文件
[root@dev22 mysql]# echo 1 >/data/mysql/logs.err
# 没权限也会报错
[root@localhost mysql]# chown -R mysql.mysql /data/mysql/
# 必须reboot
[root@localhost mysql]# reboot
[root@dev22 mysql]# service mysql start
Starting MySQL..                                           [确定]
[root@dev22 mysql]# 

登录并修改密码

ps: 如果/root/.mysql_secret 有密码,可用密码登录
# 如果用/root/.mysql_secret登录不了,请尝试使用免密登录
[root@dev22 data]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> set PASSWORD=PASSWORD('jfcf!@#$');
mysql>exit

开启远程访问

#修改密码
mysql> UPDATE mysql.user SET Password=PASSWORD('jfcf!@#$') where USER='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 4  Changed: 3  Warnings: 0
# 开启远程访问
mysql> update mysql. user set host='%' where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
#刷新权限使生效
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

设置开机启动

[root@dev22 data]# chkconfig mysql on
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值