Mysql二进制包部署(无需root权限)


1.解压安装包

tar -zxvf mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz

 

2.更改目录名称

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

 

3.进入mysql并创建目录

mkdir log tmp var data conf

 

4.把创建的目录用户和用户组更改为hadoop

chown hadoop:hadoop log tmp var data
chown -R hadoop data log var tmp

5.更改my.cnf配置文件

vi /home/hadoop/mysql/conf/my.cnf
[mysqld]
log-bin                            = mysql-bin
server-id                          = 1
user                               = hadoop
port                               = 3306
key_buffer_size                    = 256M
max_allowed_packet                 = 256M
slave_max_allowed_packet           = 256M
table_open_cache                   = 512
sort_buffer_size                   = 2M
net_buffer_length                  = 8K
read_buffer_size                   = 2M
read_rnd_buffer_size               = 512K
myisam_sort_buffer_size            = 64M
thread_cache_size                  = 64
query_cache_size                   = 64M
max_connections                    = 32000
tmp_table_size                     = 128M
long_query_time                    = 3
slow_query_log
innodb_buffer_pool_size            = 7000M	#如果机器只有mysql,建议设置为物理内存的75%
innodb_flush_log_at_trx_commit     = 0
innodb_flush_method                = O_DIRECT
innodb_file_format                 = barracuda
innodb_log_file_size               = 1G
innodb_log_files_in_group          = 3
character_set_server               = utf8
log_timestamps                     = SYSTEM
#have_statement_timeout             = NO
############### PATH ##############
basedir                            = /home/hadoop/mysql
datadir                            = /home/hadoop/mysql/data
tmpdir                             = /home/hadoop/mysql/tmp
socket                             = /home/hadoop/mysql/var/mysql.sock
pid_file                           = /home/hadoop/mysql/var/mysql.pid
general_log_file                   = /home/hadoop/mysql/log/general.log
innodb_data_home_dir               = /home/hadoop/mysql/data
slow_query_log_file                = /home/hadoop/mysql/log/slow.log
log_error                          = /home/hadoop/mysql/log/error.log
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysql]
default-character-set = utf8
[client]
default-character-set = utf8

 

6.执行初始化操作

bin/mysqld --initialize --basedir=/home/hadoop/mysql/ --datadir=/home/hadoop/mysql/data --user=hadoop  --socket=/home/hadoop/mysql/var --port=3306

如果初始化没有打印出日志 查看是否有/etc/my.cnf 默认读取了该配置

初始化后会在控制台打印出初始密码,一般就是最后几个字符,先记录下来。

–basedir 指定mysql安装目录

–datadi 指定data目录

–user 指定用户

–socket 指定socket文件存放位置

–port 指定启动端口

7.启动MySQL服务

nohup bin/mysqld_safe --defaults-file=/home/hadoop/mysql/conf/my.cnf --socket=/home/hadoop/mysql/var/mysql.sock &

 

8.登陆

  bin/mysql -u root -S /home/hadoop/mysql/var/mysql.sock -p

输入刚才记录的初始密码

9.修改密码

set password=password('123456');

 

10.如需使用 mysql -u -p 方式登陆 需要执行以下操作

ln -s /home/hadoop/mysql/var/mysql.sock /tmp/mysql.sock

 

11.设置环境变量

export MYSQL_HOME=/home/hadoop/mysql
export PATH=$MYSQL_HOME/bin:$PATH

 

12.配置远程登陆权限

grant all privileges on *.* to root@'%' identified by '123456';
flush privileges;

查看是否成功

use mysql;
select host,user from user;

Mysql二进制包部署(无需root权限)

 

如果有root权限 可以设置开机启动

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

添加到系统服务

cp mysql.server /etc/init.d/mysqld
cd /etc/init.d/
chkconfig --add mysqld #将mysql加到启动服务列表里

创建用户

create user 'meta'@'%' identified by 'meta2015';

授予权限

grant all on *.* to meta@'%';

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/291614.html

(0)
上一篇 2022年10月22日
下一篇 2022年10月22日

相关推荐

发表回复

登录后才能评论