阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Red Hat Linux安装单机版MySQL数据库

128次阅读
没有评论

共计 7703 个字符,预计需要花费 20 分钟才能阅读完成。

在 Red Hat Linux 下载安装单机版 MySQL 数据库步骤。

yum 安装依赖包 yum 配置安装  http://www.linuxidc.com/Linux/2017-02/140205.htm
yum install wget gcc gcc-c++ make cmake ncurses-devel libtool zilib-devel -y

  • 把下载的安装包移动到 /usr/local/ 下。

  • 解压
    tar zxvf MySQL-5.7.14-Linux-glibc2.5-i686.tar.gz

  • 添加系统 mysql 组和 mysql 用户
    groupadd mysql
    useradd -r -g mysql mysql

  • 拷贝配置文件
    cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

  • 修改配置文件

[root@orcl mysql]# vim /etc/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 = 22101 #端口
socket = /var/lib/mysql/mysql.sock
default-character-set = utf8

[mysqld]
port = 22101# 端口
datadir=/usr/local/mysql/data #数据位置
socket=/var/lib/mysql/mysql.sock
character-set-server = utf8 #server 级别字符集
collation-server = utf8_unicode_ci 字符编码
max_connections=1000 最大并发连接数
lower_case_table_names=1 不区分大小写
sql_mode=NO_ENGINE_SUBSTITUTION sql 校验机制
wait-timeout             = 28800 #等待关闭连接的时间
interactive-timeout      = 28800 #关闭连接之前,允许 interactive_timeout(取代了 wait_timeout)秒的不活动时间
default-storage-engine   = InnoDB #默认存储
[mysql]
no-auto-rehash #允许通过 TAB 键提示
default-character-set = utf8
# 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

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....

# 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 

#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  1. 综合操作
 创建数据 data 目录并修改权限
[root@orcl mysql]# mkdir data
[root@orcl mysql]# chown -R mysql.mysql .
[root@orcl mysql]# ll
total 56
drwxr-xr-x  2 mysql mysql  4096 Jul 12  2016 bin
-rw-r--r--  1 mysql mysql 17987 Jul 12  2016 COPYING
drwxr-xr-x  2 mysql mysql  4096 Feb  4 21:49 data
drwxr-xr-x  2 mysql mysql  4096 Jul 12  2016 docs
drwxr-xr-x  3 mysql mysql  4096 Jul 12  2016 include
drwxr-xr-x  5 mysql mysql  4096 Jul 12  2016 lib
drwxr-xr-x  4 mysql mysql  4096 Jul 12  2016 man
-rw-r--r--  1 mysql mysql  2478 Jul 12  2016 README
drwxr-xr-x 28 mysql mysql  4096 Jul 12  2016 share
drwxr-xr-x  2 mysql mysql  4096 Jul 12  2016 support-files
切换目录,并初始化数据库(nunaSZDJn1,/ 为初始密码 牢记)[root@orcl bin]#cd /usr/local/mysql/bin
[root@orcl bin]# ./mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --initialize
2017-02-04T13:50:51.147996Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-02-04T13:50:51.155737Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2017-02-04T13:50:51.557455Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-02-04T13:50:51.627576Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-02-04T13:50:51.704370Z 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: f0ed6926-eae0-11e6-a746-005056be5b20.
2017-02-04T13:50:51.706481Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-02-04T13:50:51.709430Z 1 [Note] A temporary password is generated for root@localhost: nunaSZDJn1,/
basedir 为安装目录 datadir 为存放数据路径

下面修改权限
[root@orcl local]# pwd
/usr/local
[root@orcl local]# ll
total 598100
drwxr-xr-x.  2 root  root       4096 Jan  8 14:06 bin
drwxr-xr-x.  2 root  root       4096 Jun 28  2011 etc
drwxr-xr-x.  2 root  root       4096 Jun 28  2011 games
drwxr-xr-x.  2 root  root       4096 Jun 28  2011 include
drwxr-xr-x.  2 root  root       4096 Jun 28  2011 lib
drwxr-xr-x.  2 root  root       4096 Jun 28  2011 libexec
drwxr-xr-x  10 mysql mysql      4096 Feb  4 21:49 mysql
-rw-r--r--   1 root  root  612408403 Feb  4 21:32 mysql-5.7.14-linux-glibc2.5-i686.tar.gz
drwxr-xr-x.  2 root  root       4096 Jun 28  2011 sbin
drwxr-xr-x.  5 root  root       4096 Jul  3  2015 share
drwxr-xr-x.  2 root  root       4096 Jun 28  2011 src
[root@orcl local]# chown -R root mysql
[root@orcl local]# ll
total 598100
drwxr-xr-x.  2 root root       4096 Jan  8 14:06 bin
drwxr-xr-x.  2 root root       4096 Jun 28  2011 etc
drwxr-xr-x.  2 root root       4096 Jun 28  2011 games
drwxr-xr-x.  2 root root       4096 Jun 28  2011 include
drwxr-xr-x.  2 root root       4096 Jun 28  2011 lib
drwxr-xr-x.  2 root root       4096 Jun 28  2011 libexec
drwxr-xr-x  10 root mysql      4096 Feb  4 21:49 mysql
-rw-r--r--   1 root root  612408403 Feb  4 21:32 mysql-5.7.14-linux-glibc2.5-i686.tar.gz
drwxr-xr-x.  2 root root       4096 Jun 28  2011 sbin
drwxr-xr-x.  5 root root       4096 Jul  3  2015 share
drwxr-xr-x.  2 root root       4096 Jun 28  2011 src
[root@orcl local]# chown -R mysql mysql/data/   将数据权限修改回来 
[root@orcl local]cd mysql/bin/
[root@orcl bin]# ./mysqld_safe --user=mysql &


再开启另一个命令窗口
[root@orcl ~]# ps -ef|grep mysql  服务起来了 
root     11624 10029  0 21:57 pts/0    00:00:00 /bin/sh ./mysqld_safe --user=mysql
mysql    11849 11624  2 21:57 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/orcl.err --pid-file=/usr/local/mysql/data/orcl.pid --socket=/var/lib/mysql/mysql.sock --port=22101
root     11907 11885  0 21:57 pts/1    00:00:00 grep mysql
[root@orcl ~]#
[root@orcl ~]# clear
[root@orcl ~]# cd /usr/local/mysql/bin/
[root@orcl bin]# ./mysql -uroot -p 进入 mysql 命令窗口回车后,需要输入初始化数据库时显示的密码 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.14

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> SET PASSWORD = PASSWORD('jfhr@rhvh23'); 修改密码
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> use mysql; 进入 mysql 数据库
Database changed
mysql> update user set host='%' where user='root'; 修改可以远程登录
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> FLUSH PRIVILEGES; 立即生效
Query OK, 0 rows affected (0.01 sec)

mysql> exit

设置软件连接
[root@orcl bin]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
[root@orcl bin]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@orcl bin]# vim /etc/init.d/mysql
修改
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
设置开机启动与服务命令
[root@orcl bin]# cd /etc/init.d/
[root@orcl init.d]# chkconfig --add mysql
[root@orcl init.d]# chkconfig --level 2345 mysql on
[root@orcl init.d]# chmod 777 mysql
[root@orcl init.d]# 
关闭第一个窗口,在第二个窗口里面删进程
[root@orcl init.d]# ps -ef|grep mysql
root     11624 10029  0 21:57 pts/0    00:00:00 /bin/sh ./mysqld_safe --user=mysql
mysql    11849 11624  0 21:57 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/orcl.err --pid-file=/usr/local/mysql/data/orcl.pid --socket=/var/lib/mysql/mysql.sock --port=22101
root     12110 11885  0 22:03 pts/1    00:00:00 vim /etc/init.d/mysql
root     12162 11885  0 22:06 pts/1    00:00:00 grep mysql
[root@orcl init.d]# kill -9 11624
[root@orcl init.d]# kill -9 11849
[root@orcl init.d]# ps -ef|grep mysql
root     12110 11885  0 22:03 pts/1    00:00:00 vim /etc/init.d/mysql
root     12167 11885  0 22:06 pts/1    00:00:00 grep mysql
[root@orcl init.d]# 
[root@orcl init.d]# service mysql start 启动数据库 
Starting MySQL  [OK]
[root@orcl init.d]# ps -ef|grep mysql 
root     12110 11885  0 22:03 pts/1    00:00:00 vim /etc/init.d/mysql
root     12211     1  0 22:07 pts/1    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/orcl.pid
mysql    12452 12211  0 22:07 pts/1    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/orcl.err --pid-file=/usr/local/mysql/data/orcl.pid --socket=/var/lib/mysql/mysql.sock --port=22101
root     12495 11885  0 22:08 pts/1    00:00:00 grep mysql
[root@orcl init.d]# 
单机版数据就到此结束,关于主从和集群会在下次更新时发布。如果出现 Starting MySQL. ERROR! The server quit without updating PID file (/usr/local/mysql/data/dxwx140.pid)
chown -R mysql:mysql data
chmod -R 755 /usr/local/mysql/data

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-02/140206.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计7703字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中