初识 MySQL —— 从安装MySQL 5.6 开始

目录

内容总览

官方文档

下载安装包

MySQL 5.6 安装

安装之后      


1 内容总览

2 官方文档

MySQL :: MySQL Documentation Archive

由于5.6版本是比较老的版本,所以需要到归档位置查找。具体的查找方式为:

  • 点击 www.mysql.com 链接
  • 点击Documentation的子菜单中的More,选择左边的'Archives',可以看到MySQL Reference Manual Archive目录。选择版本为5.6的即可,打开之后也可以下载到本地。


3 下载安装包

  • 依然在www.mysql.com主页,选择downloads,
  • 一直往下拉页面,找到最下面的MySQL Community(GPL) Downloads

  • 选择MySQL Community Server。这里下载社区版,不用下载企业版。

  • 点击MySQL Community Server之后,选择archives。在该页面填写要下载的数据库版本为5.6.51(可以根据自己需求选择其它版本),操作系统选择Linux-Generic,OS Version:选择的64位。最后点击右边的Download下载即可。

4 MySQL 5.6 安装

【参考官档内容】

Installing MySQL on Unix/Linux Using Generic Binaries

$> groupadd mysql
83 Create a mysql User and Group
$> useradd -r -g mysql -s /bin/false mysql
$> cd /usr/local
$> tar zxvf /path/to/mysql-VERSION-OS .tar.gz
$> ln -s full-path-to-mysql-VERSION-OS mysql
$> cd mysql
$> scripts/mysql_install_db --user=mysql
$> bin/mysqld_safe --user=mysql &
# Next command is optional
$> cp support-files/mysql.server /etc/init.d/mysql.server
  • 部署环境

一台vmware虚拟机

Centos 7.6 

IP:192.168.6.222

  • 创建组和用户

[root@dba soft]# groupadd mysql
[root@dba soft]# useradd -r -g mysql -s /bin/false mysql   

  • 使用xftp将软件包上传到服务器

创建/root/soft目录

[root@dba ~]# mkdir soft

使用xftp将安装包mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz上传到/root/soft目录。

[root@dba soft]# ll /root/soft/
total 333600
-rw-r--r--. 1 root root 341603885 Mar 13 17:45 mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz

  •  解压安装包到/usr/local目录

[root@dba soft]# tar -zxvf mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz  -C /usr/local

[root@dba soft]# ll /usr/local | grep mysql
drwxr-xr-x. 13 root root 191 Mar 13 18:20 mysql-5.6.51-linux-glibc2.12-x86_64

  •  软链接到/usr/local/mysql

[root@dba local]# ln -s mysql-5.6.51-linux-glibc2.12-x86_64/ mysql

  • 设置安装目录所属组为root:mysql

[root@dba local]# chown root:mysql -R mysql-5.6.51-linux-glibc2.12-x86_64/

  •  创建数据目录用来存放数据

[root@dba local]# mkdir -p /data/mysql
[root@dba local]# chown mysql:mysql /data -R

  •  修改配置文/etc/my.cnf

[root@dba local]# cat /etc/my.cnf | grep -v '#'
[mysqld]
datadir=/data/mysql

socket=/data/mysql/mysql.sock

[mysqld_safe]
log-error=/data/mysql/error.log

  • 数据库初始化

[root@dba local]# cd /usr/local/mysql
[root@dba mysql]# scripts/mysql_install_db --user=mysql

Installing MySQL system tables...2024-03-13 20:46:29 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2024-03-13 20:46:29 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2024-03-13 20:46:29 0 [Note] ./bin/mysqld (mysqld 5.6.51) starting as process 64511 ...
2024-03-13 20:46:29 64511 [Note] InnoDB: Using atomics to ref count buffer pool pages
2024-03-13 20:46:29 64511 [Note] InnoDB: The InnoDB memory heap is disabled
2024-03-13 20:46:29 64511 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2024-03-13 20:46:29 64511 [Note] InnoDB: Memory barrier is not used
2024-03-13 20:46:29 64511 [Note] InnoDB: Compressed tables use zlib 1.2.11
2024-03-13 20:46:29 64511 [Note] InnoDB: Using Linux native AIO
2024-03-13 20:46:29 64511 [Note] InnoDB: Using CPU crc32 instructions
2024-03-13 20:46:29 64511 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2024-03-13 20:46:29 64511 [Note] InnoDB: Completed initialization of buffer pool
2024-03-13 20:46:29 64511 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2024-03-13 20:46:29 64511 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2024-03-13 20:46:29 64511 [Note] InnoDB: Database physically writes the file full: wait...
2024-03-13 20:46:29 64511 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2024-03-13 20:46:29 64511 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2024-03-13 20:46:30 64511 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2024-03-13 20:46:30 64511 [Warning] InnoDB: New log files created, LSN=45781
2024-03-13 20:46:30 64511 [Note] InnoDB: Doublewrite buffer not found: creating new
2024-03-13 20:46:30 64511 [Note] InnoDB: Doublewrite buffer created
2024-03-13 20:46:30 64511 [Note] InnoDB: 128 rollback segment(s) are active.
2024-03-13 20:46:30 64511 [Warning] InnoDB: Creating foreign key constraint system tables.
2024-03-13 20:46:30 64511 [Note] InnoDB: Foreign key constraint system tables created
2024-03-13 20:46:30 64511 [Note] InnoDB: Creating tablespace and datafile system tables.
2024-03-13 20:46:30 64511 [Note] InnoDB: Tablespace and datafile system tables created.
2024-03-13 20:46:30 64511 [Note] InnoDB: Waiting for purge to start
2024-03-13 20:46:30 64511 [Note] InnoDB: 5.6.51 started; log sequence number 0
2024-03-13 20:46:30 64511 [Note] RSA private key file not found: /data/mysql//private_key.pem. Some authentication plugins will not work.
2024-03-13 20:46:30 64511 [Note] RSA public key file not found: /data/mysql//public_key.pem. Some authentication plugins will not work.
2024-03-13 20:46:30 64511 [Note] Binlog end
2024-03-13 20:46:30 64511 [Note] InnoDB: FTS optimize thread exiting.
2024-03-13 20:46:30 64511 [Note] InnoDB: Starting shutdown...
2024-03-13 20:46:32 64511 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK

Filling help tables...2024-03-13 20:46:32 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2024-03-13 20:46:32 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2024-03-13 20:46:32 0 [Note] ./bin/mysqld (mysqld 5.6.51) starting as process 64533 ...
2024-03-13 20:46:32 64533 [Note] InnoDB: Using atomics to ref count buffer pool pages
2024-03-13 20:46:32 64533 [Note] InnoDB: The InnoDB memory heap is disabled
2024-03-13 20:46:32 64533 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2024-03-13 20:46:32 64533 [Note] InnoDB: Memory barrier is not used
2024-03-13 20:46:32 64533 [Note] InnoDB: Compressed tables use zlib 1.2.11
2024-03-13 20:46:32 64533 [Note] InnoDB: Using Linux native AIO
2024-03-13 20:46:32 64533 [Note] InnoDB: Using CPU crc32 instructions
2024-03-13 20:46:32 64533 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2024-03-13 20:46:32 64533 [Note] InnoDB: Completed initialization of buffer pool
2024-03-13 20:46:32 64533 [Note] InnoDB: Highest supported file format is Barracuda.
2024-03-13 20:46:32 64533 [Note] InnoDB: 128 rollback segment(s) are active.
2024-03-13 20:46:32 64533 [Note] InnoDB: Waiting for purge to start
2024-03-13 20:46:32 64533 [Note] InnoDB: 5.6.51 started; log sequence number 1625977
2024-03-13 20:46:32 64533 [Note] RSA private key file not found: /data/mysql//private_key.pem. Some authentication plugins will not work.
2024-03-13 20:46:32 64533 [Note] RSA public key file not found: /data/mysql//public_key.pem. Some authentication plugins will not work.
2024-03-13 20:46:32 64533 [Note] Binlog end
2024-03-13 20:46:32 64533 [Note] InnoDB: FTS optimize thread exiting.
2024-03-13 20:46:32 64533 [Note] InnoDB: Starting shutdown...
2024-03-13 20:46:34 64533 [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:

  ./bin/mysqladmin -u root password 'new-password'
  ./bin/mysqladmin -u root -h dba.enmotech.com password 'new-password'

Alternatively you can run:

  ./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 . ; ./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

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

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
 

  • 启动服务

[root@dba mysql]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
[1] 64673
[root@dba mysql]# Logging to '/data/mysql/error.log'.
240313 20:49:55 mysqld_safe Starting mysqld daemon with databases from /data/mysql

5 安装之后      

  • 查看数据库进程

[root@dba mysql]# ps -ef | grep mysql
root      64673  10311  0 20:49 pts/0    00:00:00 /bin/sh bin/mysqld_safe --user=mysql
mysql     64795  64673 13 20:49 pts/0    00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/error.log --pid-file=dba.enmotech.com.pid --socket=/data/mysql/mysql.sock
root      64828  10311  0 20:50 pts/0    00:00:00 grep --color=auto mysql

  •  修改环境变量

[root@dba ~]# vi /etc/profile

末尾添加:

export PATH=/usr/local/mysql/bin:$PATH

按ESC,输入:wq回车保存退出。

生效变量:

[root@dba ~]# source  /etc/profile

或者重新用root用户登陆。

  • 登陆数据库

[root@dba ~]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

  • 解决以上报错:

[root@dba ~]# find / | grep mysql.sock
/usr/local/mysql-5.6.51-linux-glibc2.12-x86_64/include/mysql/psi/mysql_socket.h
/data/mysql/mysql.sock
[root@dba ~]# ln -s /data/mysql/mysql.sock /tmp/mysql.sock

  • 重新登陆:

[root@dba ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.51 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, 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> 

  • 查看数据库

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> 

  • 设置服务开机自启动

[root@dba mysql]# cd /usr/local/mysql-5.6.51-linux-glibc2.12-x86_64/support-files/
[root@dba support-files]# ls
binary-configure  my-default.cnf       mysql-log-rotate
magic             mysqld_multi.server  mysql.server
[root@dba support-files]# cp mysql.server /etc/rc.d/init.d/
[root@dba support-files]# service mysql.server status

[root@dba init.d]# service mysql.server status
 SUCCESS! MySQL running (64795)

[root@dba support-files]# chkconfig mysql.server on
[root@dba support-files]# chkconfig --list | grep mysql.server

[root@dba support-files]# chkconfig mysql.server on

[root@dba support-files]# chkconfig --list | grep mysql.server

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysql.server    0:off   1:off   2:on    3:on    4:on    5:on    6:off

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值