MySql教程

MYSQL安装(无需root权限)

本文主要是介绍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]
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

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

--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;

image

 

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

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

创建用户

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

授予权限

grant all on *.* to meta@'%';
这篇关于MYSQL安装(无需root权限)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!