1.部署mysql 方法:
①RPM安装
②tar安装
一.介绍RPM安装:
1.通过yum安装
yum install -y mysql-server.x86_64
通过yum安装mysql服务器,版本为x86_64
yum install -y mysql.x86_64
安装mysql
service mysql start
启动mysql
Entrpassword:回车键
这里密码为空,可以直接回车进去
2.RPM卸载:
rpm -qa | grep mysql
找到所安装的mysql
mysql-libs-5.1.73-8.el6_8.x86_64
mysql-server-5.1.73-8.el6_8.x86_64
mysql-5.1.73-8.el6_8.x86_64
其中libs可以不卸载
可通过rpm -e 挨个卸载其余两个,例如:
rpm -e mysql-5.1.73-8.el6_8.x86_64
二.tar 定制化安装
1.rz上传
[root@sht-sgmhadoopnn-01 ~]# cd /usr/local
mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz
在linux命令行输入“rz”选择安装包进行上传
2.校验安装包
md5sum
md5sum + 安装包
3.检查所在机器是否有安装的mysql
ps -ef|grep mysqld
rpm -qa |grep -i mysql
4.tar 解压安装包
tar -xzvf mysql-5.6.23-linux-glibc2.5-
x86_64.tar.gz
5.mv 重命名
mv mysql-5.6.23-linux-glibc2.5-x86_64 mysql
6.groupadd 创建用户组
groupadd -g 101 dba
在dba下创建了用户组名为101的用户组
useradd -u 514 -g dba -G root -d /usr/local/mysql mysqladmin
创建了用户514,主组为dab,所在组为root,所在位置:-d /usr/local/mysql
用户名为mysqladmin
7.查看所创建的用户
id mysqladmin
uid=514(mysqladmin) gid=101(dba) groups=101(dba),0(root)
8.配置环境变量:
cp /etc/skel/.* /usr/local/mysql
cp: omitting directory `/etc/skel/.'
cp: omitting directory `/etc/skel/..'
cp: omitting directory `/etc/skel/.mozilla'
如果没有配置环境变量,是这样的:
su - mysqladmin
-.bash-4.1#
9.系统需要运行,需要配置文件,在vi下进入编辑模式:my.cnf
[root@sht-sgmhadoopnn-01 mysql]# cd /etc/
[root@sht-sgmhadoopnn-01 etc]# touch my.cnf
[root@sht-sgmhadoopnn-01 etc]# vi my.cnf
[client]
port = 3306
socket = /usr/local/mysql/data/mysql.sock
[mysqld]
port = 3306
socket = /usr/local/mysql/data/mysql.sock
skip-external-locking
key_buffer_size = 256M
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 4M
query_cache_size= 32M
max_allowed_packet = 16M
myisam_sort_buffer_size=128M
tmp_table_size=32M
table_open_cache = 512
thread_cache_size = 8
wait_timeout = 86400
interactive_timeout = 86400
max_connections = 600
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 32
#isolation level and default engine
default-storage-engine = INNODB
transaction-isolation = READ-COMMITTED
server-id = 1
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
pid-file = /usr/local/mysql/data/hostname.pid
#open performance schema
log-warnings
sysdate-is-now
binlog_format = MIXED
log_bin_trust_function_creators=1
log-error = /usr/local/mysql/data/hostname.err
log-bin=/usr/local/mysql/arch/mysql-bin
#other logs
#general_log =1
#general_log_file = /usr/local/mysql/data/general_log.err
#slow_query_log=1
#slow_query_log_file=/usr/local/mysql/data/slow_log.err
#for replication slave
#log-slave-updates
#sync_binlog = 1
#for innodb options
innodb_data_home_dir = /usr/local/mysql/data/
innodb_data_file_path = ibdata1:500M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/arch
innodb_log_files_in_group = 2
innodb_log_file_size = 200M
#生产上 机械硬盘 sata盘 5000r 7200 10000 15000 ==> ssd 生产
innodb_buffer_pool_size = 1024M
innodb_additional_mem_pool_size = 50M
innodb_log_buffer_size = 16M
innodb_lock_wait_timeout = 100
#innodb_thread_concurrency = 0
innodb_flush_log_at_trx_commit = 1
innodb_locks_unsafe_for_binlog=1
#innodb io features: add for mysql5.5.8
performance_schema
innodb_read_io_threads=4
innodb-write-io-threads=4
innodb-io-capacity=200
#purge threads change default(0) to 1 for purge
innodb_purge_threads=1
innodb_use_native_aio=on
#case-sensitive file names and separate tablespace
innodb_file_per_table = 1
lower_case_table_names=1
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[mysqlhotcopy]
interactive-timeout
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
注意:根据自己机器内存调整mysql内存参数:
innodb_buffer_pool_size = 50%
一般为电脑内存的百分之50
[client] 为客户端
[mysqld]为服务端
10.用户归属与用户权限设置
[root@sht-sgmhadoopnn-01 local]# chown mysqladmin:dba /etc/my.cnf
[root@sht-sgmhadoopnn-01 local]# chmod 640 /etc/my.cnf
查看my.cnf文件:
[root@sht-sgmhadoopnn-01 etc]# ll my.cnf
-rw-r----- 1 mysqladmin dba 2201 Aug 25 23:09 my.cnf
[root@sht-sgmhadoopnn-01 local]# chown -R mysqladmin:dba /usr/local/mysql
[root@sht-sgmhadoopnn-01 local]# chmod -R 755 /usr/local/mysql
切换用户:
[root@sht-sgmhadoopnn-01 local]# su - mysqladmin
查看所在路径:
[mysqladmin@sht-sgmhadoopnn-01 ~]$ pwd
/usr/local/mysql
11.#创建arch目录 存储binlog 归档日志
[mysqladmin@sht-sgmhadoopnn-01 ~]$ mkdir arch
[mysqladmin@sht-sgmhadoopnn-01 ~]$ scripts/mysql_install_db \
--user=mysqladmin \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
12.配置MyS QL服务和启动自动启动
[root@sht-sgmhadoopnn-01 ~]# cd /usr/local/mysql
[root@sht-sgmhadoopnn-01 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysql
#赋予可执行权限
[root@sht-sgmhadoopnn-01 mysql]# chmod +x /etc/rc.d/init.d/mysql
#删除服务
[root@sht-sgmhadoopnn-01 mysql]# chkconfig --del mysql
#添加服务
[root@sht-sgmhadoopnn-01 mysql]# chkconfig --add mysql
[root@sht-sgmhadoopnn-01 mysql]# chkconfig --level 345 mysql on
编写自动启动脚本:
[root@sht-sgmhadoopnn-01 mysql]# vi /etc/rc.local
进入编辑模式
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
su - mysqladmin -c "/etc/init.d/mysql start --federated"
12.启动mysql并查看进程和收听
[root@sht-sgmhadoopnn-01 mysql]# su - mysqladmin
[mysqladmin@sht-sgmhadoopnn-01 ~]$ pwd
/usr/local/mysql
[mysqladmin@sht-sgmhadoopnn-01 ~]$ rm -rf my.cnf
[mysqladmin@hadoop001 ~]$ service mysql start
启动mysql,以下为成功:
Starting MySQL. [ OK ]
[mysqladmin@hadoop001 ~]$
[mysqladmin@hadoop001 ~]$ service mysql status
MySQL running (3625) [ OK ]
13.检查所安装的muysql的端口号
[mysqladmin@sht-sgmhadoopnn-01 ~]$ ps -ef|grep mysqld
[mysqladmin@sht-sgmhadoopnn-01 ~]$ netstat -tulnp | grep mysql
端口号为 3306
14.进入mysql
su - mysqladmin
mysql -uroot -p
输入密码:
15.进入数据库
show databases ;
16.更新密码,清空
use mysql 切换数据库
update user set password=password('123456') where user='root';
修改user表中的对象root的密码设置为编码下的123456
查看密码与用户:
select host,user,password from user;
删除user表中空的用户:
delete from user where user='';
#针对用户 权限的操作语句 养成习惯 都最后一步执行刷新权限:flush privileges;
17.配置mysql的家目录/路径展示位置提到首行
[mysqladmin@sht-sgmhadoopnn-01 ~]$ cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
export MYSQL_HOME=/usr/local/mysql
export RT PATH=${MYSQL_HOME}/bin:$PATH
PS1=`uname -n`":"'$USER'":"'$PWD'":>"; export PS1