学习linux第三十九天

安装mysql

[root@hanlinxy ~]# uname -a
Linux hanlinxy 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@hanlinxy ~]# cd /usr/local/src
[root@hanlinxy src]# ls
apr-1.6.3 httpd-2.4.33 inotify-tools-3.13
apr-1.6.3.tar.gz httpd-2.4.33.tar.gz inotify-tools-3.13.tar.gz
httpd-2.2.9 index.html
httpd-2.2.9.tar.gz index.html.1
[root@hanlinxy src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
--2018-07-17 17:46:29-- http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
正在解析主机 mirrors.sohu.com (mirrors.sohu.com)... 221.236.12.140
正在连接 mirrors.sohu.com (mirrors.sohu.com)|221.236.12.140|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:316320366 (302M) [application/octet-stream]
正在保存至: “mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz”

 

[root@hanlinxy mysql]# tar -xzvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz

[root@hanlinxy src]# ls
apr-1.6.3 httpd-2.2.9 httpd-2.4.33 index.html inotify-tools-3.13 mysql-5.6.36-linux-glibc2.5-x86_64
apr-1.6.3.tar.gz httpd-2.2.9.tar.gz httpd-2.4.33.tar.gz index.html.1 inotify-tools-3.13.tar.gz mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
[root@hanlinxy src]# mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql
[root@hanlinxy src]# cd !$
cd /usr/local/mysql
[root@hanlinxy mysql]# ls
bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files
[root@hanlinxy mysql]# useradd mysql    新建MySQL账号
[root@hanlinxy mysql]# mkdir data/mysql 创建数据存储目录

[root@hanlinxy mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/mysql(有可能会提示缺少perl-data-dumper)初始化mysql

[root@hanlinxy mysql]# echo $? (判断上一条命令是否正确,0为正确,1为错误)或者看过程中有没有出现两个ok
0
[root@hanlinxy mysql]# cp support-files/my-default.cnf /etc/my.cnf (把mysql路径下support-files里面的配置文件模板复制到指定路径并改名)
[root@hanlinxy mysql]# cat !$
 

[root@hanlinxy mysql]# cp support-files/mysql.server /etc/init.d/mysqld (复制启动脚本到指定路径)
[root@hanlinxy mysql]# vim !$
vim /etc/init.d/mysqld (自定义启动脚本)

basedir=/usr/local/mysql 

datadir=data/mysql

 

[root@hanlinxy mysql]# cd /etc/init.d/
[root@hanlinxy init.d]# ls
functions mysqld netconsole network README xy
[root@hanlinxy init.d]# chmod 755 mysqld 
[root@hanlinxy init.d]# chkconfig --add mysqld (启动服务添加mysqld)
[root@hanlinxy init.d]# chkconfig --list (列出启动的服务项)

注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。 

要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。

mysqld 0:关 1:关 2:开 3:开 4:开 5:开 6:关

netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
xy 0:关 1:关 2:开 3:开 4:开 5:开 6:关
 

[root@hanlinxy mysql]# service mysqld start (启动mysqld)
Starting MySQL.Logging to '/usr/local/mysql/data/mysql/hanlinxy.err'.
SUCCESS! 
[root@hanlinxy mysql]# cat /usr/local/mysql/data/mysql/hanlinxy.err
2018-07-18 09:22:40 13549 [Note] Plugin 'FEDERATED' is disabled.
2018-07-18 09:22:40 13549 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-07-18 09:22:40 13549 [Note] InnoDB: The InnoDB memory heap is disabled
2018-07-18 09:22:40 13549 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-07-18 09:22:40 13549 [Note] InnoDB: Memory barrier is not used
2018-07-18 09:22:40 13549 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-07-18 09:22:40 13549 [Note] InnoDB: Using Linux native AIO
2018-07-18 09:22:40 13549 [Note] InnoDB: Using CPU crc32 instructions
2018-07-18 09:22:40 13549 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-07-18 09:22:40 13549 [Note] InnoDB: Completed initialization of buffer pool
2018-07-18 09:22:40 13549 [Note] InnoDB: Highest supported file format is Barracuda.
2018-07-18 09:22:40 13549 [Note] InnoDB: 128 rollback segment(s) are active.
2018-07-18 09:22:40 13549 [Note] InnoDB: Waiting for purge to start
2018-07-18 09:22:40 13549 [Note] InnoDB: 5.6.36 started; log sequence number 1626007
2018-07-18 09:22:40 13549 [Note] Server hostname (bind-address): '*'; port: 3306
2018-07-18 09:22:40 13549 [Note] IPv6 is available.
2018-07-18 09:22:40 13549 [Note] - '::' resolves to '::';

vim /usr/local/mysql/my.cnf

# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data/mysql
port = 3306
server_id = 128
socket = /tmp/mysql.sock

# 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

[root@hanlinxy mysql]# vim /etc/init.d/mysqld

basedir=/usr/local/mysql

datadir=/data/mysql
 

检测mysql运行状态

[root@hanlinxy mysql]# ps -aux |grep mysqld
root 13439 0.0 0.0 11816 1604 pts/1 S 09:22 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data/mysql --pid-file=/usr/local/mysql/data/mysql/hanlinxy.pid
mysql 13549 0.7 20.5 1302904 449620 pts/1 Sl 09:22 0:10 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/mysql/hanlinxy.err --pid-file=/usr/local/mysql/data/mysql/hanlinxy.pid
root 13868 0.0 0.0 112720 984 pts/1 S+ 09:44 0:00 grep --color=auto mysqld

[root@hanlinxy mysql]# netstat -lnp |grep 3306
tcp6 0 0 :::3306 :::* LISTEN 13549/mysqld 

 

 

 /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data/mysql --pid-file=/usr/local/mysql/data/mysql/hanlinxy.pid
当mysql启动脚本出问题的时候可以手动启动

[root@hanlinxy httpd-2.4.34]# /usr/local/mysql/bin/mysqld_safe --default-file=/etc/my.cnf (设定默认配置文件)--user=mysql(设定用户) --datadir=/data/mysql (设定数据目录)

转载于:https://my.oschina.net/u/3867255/blog/1884577

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值