mysql学习心得之二进制安装(4)

前序

mysql的安装方式有三种:1.rpm包安装。2.二进制安装。3.源代码编译安装。

之前已经用rpm包安装过了,这次用二进制安装的方式安装。

本次安装版本5.5.47,后面发现5.7的安装有了一定的变化,5.7.6之前和只有的安装步骤也有点不同。具体参考官方文档。

官方文档里面这样说的:

Oracle provides a set of binary distributions of MySQL. These include generic binary distributions in the form of compressed tar files (files with a .tar.gz extension) for a number of platforms, and binaries in platform-specific package formats for selected platforms.

oracle提供了一系列的mysql的二进制文件。在压缩包内,它包括了一些普通的二进制文件以及一些所选平台特有的文件,这些文件在tar包中。

在安装之前,文档里面有几个小小的warning。

If you have previously installed MySQL using your operating system native package management system, such as yum or apt-get, you may experience problems installing using a native binary. Make sure your previous MySQL installation has been removed entirely (using your package management system), and that any additional files, such as old versions of your data files, have also been removed. You should also check for configuration files such as /etc/my.cnf or the /etc/mysql directory and delete them.

如果你在你的系统中已经用了本地的包管理工具来安装的mysql,比如yum或者apt-get,你可能会经历一些问题。确保你之前的mysql安装已经完全的删除了。比如之前的数据文件的旧版本。而且你还得检查你的配置文件,比如/etc/my.cnf或者/etc/mysql目录并且删除他们。

MySQL has a dependency on the libaio library. Data directory initialization and subsequent server startup steps will fail if this library is not installed locally.If necessary, install it using the appropriate package manager. For example, on Yum-based systems:

shell> yum search libaio # search for info
shell> yum install libaio # install library


Or, on APT-based systems:
shell> apt-cache search libaio # search for info
shell> apt-get install libaio1 # install library


msql对libaio包也有依赖。如果这个包不安装的话,那么数据目录以及一些子进程的开启将会失败。

要使用mysql的二进制文件安装的话,那么你得使用如下的一些命令。

shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
# Next command is optional
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
这些命令假设你都是使用root用户登入系统的。以上都是官方文档里面的内容,我觉得在安装过程中的任何一个提示都得注意,不然就会掉入坑中。

下面是我根据官方文档具体的步骤做的一边,中间也加了几条文档没有的命令。

1.创建一个msql用户和用户组

如果你的系统还没有用户和用户组用来运行mysqld命令的话,你可能需要创建他们。下面的命令是用来增加一个mysql的用户组和mysql的用户。

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

2.修改hosts文件

添加127.0.0.1 主机名到hosts文件中,不然安装会不成功。

3.获取并解压你的二进制安装包

选择一个目录你用来解压二进制包,并且帮当前路径换成该目录。举例,这里是使用了/usr/local。因此,假设你有权限在/usr/local这个目录创建文件或目录。
[root@SY local]# tar zxvf mysql-5.5.47-linux2.6-x86_64.tar.gz
[root@SY local]# ln -s mysql-5.5.47-linux2.6-x86_64 mysql

4.安装libaio.so包

[root@SY local]# rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm 
warning: libaio-0.3.107-10.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Preparing...                ########################################### [100%]
   1:libaio                 ########################################### [100%]

5.执行先前的操作

[root@SY local]# cd mysql
[root@SY mysql]# chown -R mysql .
[root@SY mysql]# chgrp -R mysql .
[root@SY mysql]# scripts/mysql_install_db --user=mysql
Installing MySQL system tables...
160104  1:26:08 [Note] ./bin/mysqld (mysqld 5.5.47) starting as process 1311 ...
OK
Filling help tables...
160104  1:26:08 [Note] ./bin/mysqld (mysqld 5.5.47) starting as process 1318 ...
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 SY 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/

[root@SY mysql]# chown -R root .
[root@SY mysql]# chown -R mysql data
[root@SY mysql]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
[root@SY mysql]# cp support-files/my-medium.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? 
[root@SY mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@SY mysql]# ./bin/mysqld_safe --user=mysql
160104 01:29:56 mysqld_safe Logging to '/var/log/mysqld.log'.
160104 01:29:56 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
160104 01:29:57 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
[root@SY mysql]# ./bin/mysqladmin -u root password 123456
./bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
[root@SY mysql]# service mysqld start
Starting MySQL.. SUCCESS! 
[root@SY mysql]# ./bin/mysqladmin -u root password 123456
[root@SY mysql]# ./bin/mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@SY mysql]# ./bin/mysql -u root -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.47 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> 
至此,安装就成功了。




















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于MySQL二进制安装,可以按照以下步骤进行操作: 1. 下载MySQL二进制文件,并将其移动到目标目录。根据引用,可以使用命令`mv mysql-5.7.30-linux-glibc2.12-x86_64 /home/mysql2/mysql`将MySQL二进制文件移动到`/home/mysql2/mysql`目录中。 2. 创建MySQL的数据目录。可以使用命令`mkdir /usr/local/mysql`创建MySQL的数据目录。根据引用,可以使用命令`mv mysql-5.7.35-linux-glibc2.12-x86_64 /usr/local/mysql`将MySQL二进制文件移动到`/usr/local/mysql`目录中。 3. 设置MySQL数据目录的所有者和权限。根据引用,可以使用命令`chown -R mysql2.mysql2 /Lcdmp3_mysqldata/ /home/mysql2`将数据目录的所有者设置为`mysql2`,组设置为`mysql2`。 请注意,以上步骤仅为示例,具体的安装步骤可能因MySQL版本或操作系统的差异而有所不同。在进行MySQL二进制安装之前,请确保已阅读并遵循官方文档或安装指南以确保正确安装和配置MySQL。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [二进制方式安装mysql](https://blog.csdn.net/qq_26711103/article/details/128559643)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [MySQL二进制安装](https://blog.csdn.net/LFCuiYs/article/details/120830896)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值