CentOS6.4 Install MySQL 5.6.45


参考:
https://zhangjh.me/2017/03/14/linux-install-mysql/

下载源码包

https://dev.mysql.com/downloads/mysql/
1552062-20190808172025736-214817868.png

解压并拷贝到/usr/local

tar -xvf mysql-5.6.45-linux-glibc2.12-x86_64.tar.gz

mv mysql-5.6.26-linux-glibc2.5-x86_64 mysql

sudo mv mysql /usr/local/mysql

创建用户和用户组

groupadd mysql

useradd -r -g mysql mysql

# 账号mysql  组mysql 密码mysql

# 给账号创建密码的方法
passwd 输入用户名
# 输入密码

改变目录权限

chown -R mysql:mysql *

╭─Mysticbinary@CentOSv64 /usr/local/mysql 
╰─$ sudo chown -R mysql:mysql *                                             9 ↵
╭─Mysticbinary@CentOSv64 /usr/local/mysql 
╰─$ ll
total 68K
drwxrwxr-x.  2 mysql mysql 4.0K Aug  8 15:11 bin
-rw-r--r--.  1 mysql mysql  18K Jun 10 18:25 COPYING
drwxrwxr-x.  3 mysql mysql 4.0K Aug  8 15:11 data
drwxrwxr-x.  2 mysql mysql 4.0K Aug  8 15:11 docs
drwxrwxr-x.  3 mysql mysql 4.0K Aug  8 15:11 include
drwxrwxr-x.  3 mysql mysql 4.0K Aug  8 15:11 lib
drwxrwxr-x.  4 mysql mysql 4.0K Aug  8 15:11 man
drwxrwxr-x. 10 mysql mysql 4.0K Aug  8 15:11 mysql-test
-rw-r--r--.  1 mysql mysql 2.5K Jun 10 18:25 README
drwxrwxr-x.  2 mysql mysql 4.0K Aug  8 15:11 scripts
drwxrwxr-x. 28 mysql mysql 4.0K Aug  8 15:11 share
drwxrwxr-x.  4 mysql mysql 4.0K Aug  8 15:11 sql-bench
drwxrwxr-x.  2 mysql mysql 4.0K Aug  8 15:11 support-files

安装

最好使用默认的/uer/local/mysql安装路径。我之前改过安装目录,导致报错太多,一个个处理真有点浪费时间的。

先了解安装的参数:

用法:/ usr / local / mysql / bin / mysql_install_db [OPTIONS]
  --basedir = path MySQL安装目录的路径。
  --cross-bootstrap供内部使用。在构建MySQL系统时使用
                       与目标不同的主机上的表。
  --datadir = path MySQL数据目录的路径。
  --force即使DNS没有,也会使mysql_install_db运行
                       工作。在这种情况下,通常授予表条目
                       使用主机名将使用IP地址。
  --ldata = path MySQL数据目录的路径。
  --rpm供内部使用。 RPM文件使用此选项
                       在MySQL安装过程中。
  --skip-name-resolve创建时使用IP地址而不是主机名
                       授予表条目。如果,此选项非常有用
                       你的DNS不起作用。
  --srcdir = path供内部使用。目录下的
                       mysql_install_db查找支持文件,如
                       错误消息文件和用于popoulating的文件
                       帮助表。
  --user = user_name用于运行mysqld的登录用户名。
                       由mysqld创建的目录将由此拥有
                       用户。您必须是root才能使用此选项。默认情况下
                       mysqld使用您当前的登录名和文件运行
                       它创建的目录将归您所有。

所有其他选项都传递给mysqld程序

启动安装命令
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

╭─Mysticbinary@CentOSv64 /usr/local/mysql 
╰─$ ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
WARNING: The host 'CentOSv64' could not be looked up with /usr/local/mysql/bin/resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !

Installing MySQL system tables...2019-08-08 15:33:18 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-08 15:33:18 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2019-08-08 15:33:18 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.45) starting as process 5975 ...
2019-08-08 15:33:18 5975 [Warning] Can't create test file /usr/local/mysql/data/CentOSv64.lower-test
2019-08-08 15:33:18 5975 [Warning] Can't create test file /usr/local/mysql/data/CentOSv64.lower-test
2019-08-08 15:33:18 5975 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)

2019-08-08 15:33:18 5975 [Warning] Buffered warning: Changed limits: table_open_cache: 431 (requested 2000)

2019-08-08 15:33:18 5975 [Note] InnoDB: Using atomics to ref count buffer pool pages
2019-08-08 15:33:18 5975 [Note] InnoDB: The InnoDB memory heap is disabled
2019-08-08 15:33:18 5975 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-08-08 15:33:18 5975 [Note] InnoDB: Memory barrier is not used
2019-08-08 15:33:18 5975 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-08-08 15:33:18 5975 [Note] InnoDB: Using Linux native AIO
2019-08-08 15:33:18 5975 [Note] InnoDB: Using CPU crc32 instructions
2019-08-08 15:33:18 5975 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2019-08-08 15:33:18 5975 [Note] InnoDB: Completed initialization of buffer pool
2019-08-08 15:33:18 7fbde70ed720  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
2019-08-08 15:33:18 7fbde70ed720  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
# 报错了!
2019-08-08 15:33:18 5975 [ERROR] InnoDB: Creating or opening ./ibdata1 failed!
2019-08-08 15:33:18 5975 [ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!
2019-08-08 15:33:18 5975 [ERROR] Plugin 'InnoDB' init function returned error.
2019-08-08 15:33:18 5975 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2019-08-08 15:33:18 5975 [ERROR] Unknown/unsupported storage engine: InnoDB
2019-08-08 15:33:18 5975 [ERROR] Aborting

2019-08-08 15:33:18 5975 [Note] Binlog end
2019-08-08 15:33:18 5975 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete

解决:
发现是没有加sudo,没有权限导致的,加上就搞定了;

╭─Mysticbinary@CentOSv64 /usr/local/mysql 
╰─$ sudo ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

# ......
2019-08-08 15:54:51 6263 [Note] Binlog end
2019-08-08 15:54:51 6263 [Note] InnoDB: FTS optimize thread exiting.
2019-08-08 15:54:51 6263 [Note] InnoDB: Starting shutdown...
2019-08-08 15:54:53 6263 [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/local/mysql/bin/mysqladmin -u root password 'new-password'
  /usr/local/mysql/bin/mysqladmin -u root -h CentOSv64 password 'new-password'

Alternatively you can run:

  /usr/local/mysql/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/local/mysql/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/local/mysql/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/local/mysql/my-new.cnf,
please compare it with your file and take the changes you need.

启动

前台启动

╭─Mysticbinary@CentOSv64 /usr/local/mysql 
╰─$ sudo ./bin/mysqld_safe 
[sudo] password for Mysticbinary: 
Logging to '/usr/local/mysql/data/CentOSv64.err'.
190808 16:07:09 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

# 前台运行的话,这里会失去shell 控制。 建议用后台方法启动

如果启动失败,可以去data目录下查看err结尾的错误日志,查看错误信息。

后台启动

sudo ./bin/mysqld_safe &

添加mysql为系统服务

sudo cp support-files/mysql.server /etc/init.d/mysql

之后就可以使用/etc/init.d/mysql start|stop|restart来管理mysql了

添加环境变量

sudo vi /etc/profile
#修改PATH=$PATH:/usr/local/mysql/bin

source /etc/profile
# 重新加载profile

添加环境变量之后即可任意目录下直接输入mysql进行连接而不用在mysql/bin目录下了。

创建mysql用户

# 如给root添加密码
mysqladmin -u root password "you new password"

#添加新用户
mysql -u root -p
#name处用用户替换,passwd处用密码替换
mysql> GRANT USAGE ON *.* TO 'name'@'localhost' IDENTIFIED BY 'passwd' WITH GRANT OPTION;

连接mysql

mysql -uroot -p
#密码 root

转载于:https://www.cnblogs.com/mysticbinary/articles/11268447.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值