Linux在Centos下通过tar解压mysql.tar.gz安装包的形式安装MySQL

4 篇文章 0 订阅

1. 下载mysql的安装包

下载地址:[ https://dev.mysql.com/downloads/file/?id=481117 ]
在这里插入图片描述

记得版本选64位,我之前在本机下载了个32位,安装出现了各种问题, 提示很多依赖包要下载,但是下载后,还是未能在安装成功,我暂时没整明白, 所以根据自己机器选择,我机器64位的!

2 建立一个普通用户及mysql用户例如xzb(必须)

1、         建立一个mysql的组
	输入命令: groupadd xzb
2、建立mysql用户,并放到mysql组
	输入命令:useradd -r -g mysql xzb
3、         给mysql用户设置密码
	输入命令:passwd xzb

其实直接useradd xzb 它默认会创建一个相同的用户组的!

注意: 需要把当前用户加入到 mysql的组中

3. 上传并解压mysql

  • 1.本地上传: 我用的是 yum -y install lrzsz 这个工具包,安装后,可以直接在本地把,安装包拖拽即可, 我用的xshell.,比如上传到/opt/software
  • 在这里插入图片描述

此时我们用root 用户登录:当然普通用户也可以

在此之前,规定一下存储路径,便于管理, 安装包一般存放于/opt 目录下, 所以我新建2个目录, 一个用于上传的安装包software, 一个用于解压后所存放的目录modules
cd /opt
mkdir modules software
在这里插入图片描述

  • 2 进行解压,并指定存放目录
    cd /opt/software
    tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /opt/modules
    -C 指定解压目录
    更改一大串名字 为 mysql
    cd /opt/modules
    mv mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz mysql

4. 配置相关的启动配置文件

  1. 复制my_default.cnf到/etc/my.cnf (mysql启动时自动读取)
    如果没有该文件, 我会在最后复制一份该文件,到时候拷贝下,更改相应的一些值就可以了
    cd /opt/modules/mysql/support-files
    在这里插入图片描述

  2. 输入命令:cp my_default.cnf /etc/my.cnf
    需要注意的地方
    在这里插入图片描述
    当然还有其他的默认参数,或者可以修改,根据自己需要来,要编辑的是/etc/my.cnf文件哦!

  3. 复制mysql.server 到/etc/init.d/
    这样在后面设置自启动文件,用chkconfig 加入
    换个名字为mysql
    cp mysql.server /etc/init.d/mysql
    需要指定一下mysql目录和存放的目录

    输入命令:vi /etc/init.d/mysql
    更改:basedir=/opt/modules/mysql
        datadir=/opt/modules/mysql/data

    在这里插入图片描述

  4. 给目录/opt/modules/mysql更改拥有者

chown -R 用户名:组名 /opt/modules/mysql

输入命令:chown -R xzb:xzb /usr/local/mysql/

在这里插入图片描述

4. 初始化mysql配置信息

进入bin目录下,执行命令
./mysqld --initialize --user=xzb --basedir=/opt/modules/mysql --datadir=/opt/modules/mysql/data

user : 是你mysql所属用户
basedir : mysql安装目录
datadir : 数据存储目录

生成出一个data目录,代表数据库已经初始化成功
这里会生成一个临时密码(保存记住,后面要用到)

在这里插入图片描述

2. 给数据库加密

输入命令:./mysql_ssl_rsa_setup --datadir=/opt/modules/mysql/data
在这里插入图片描述

3. 启动mysql
输入命令:./mysqld_safe --user=xzb &
&符号:把当前进程丢给后台

5.登录mysql

进入bin目录下
输入命令:./mysql -uroot -p

然后输入你的临时密码
在这里插入图片描述

2. 修改密码
输入命令:set password=password(‘你的密码’);

6. window远程访问Linux虚拟机的mysql

  1. 首先需要关闭防火墙, 或者在/etc/sysconfig/iptables 下开放3306自己设置的端口号,然后 service iptables restart 重启服务
    2. 给用户授权
    输入命令:grant all privileges on . to root @"%" identified by ‘123456’ WITH GRANT OPTION;

  2. 基于安全考虑root账户一般只能本地访问,但是在开发过程中可能需要打开root的远程访问权限。下面是基本的步骤:

     1、登录到mysql中,为root进行远程访问的授权,执行下面的命令:
     mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";
     mysql> flush privileges;
     GRANT ALL PRIVILEGES ON *.* TO root@"localhost" IDENTIFIED BY "root";
     mysql> flush privileges;
    
  3. 远程连接
    eg . window远程连接
    输入命令:mysql -hIP地址 -uroot -p123456

7. mysql 设置启动

  • 1.使用 ps 和 kill命令 关闭mysql(刚才启动的安全服务)
  • 2.设置MYSQL 服务

cp support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
systemctl enable mysql.service

  • 3.以服务方式启动/关闭/重启

启动: # service mysql start
关闭: # service mysql stop
重启: # service mysql restart

1、  添加服务mysql

输入命令:chkconfig --add mysql
2、  设置服务开机自启

输入命令:chkconfig mysql on

8. mysql 配置环境变量

输入命令:vi /etc/profile
在这里插入图片描述

此处mysql就已经配置完毕!!!, 大家可以试试

9 mysql 创建用户/授权/

mysql 创建一个用户 hail,密码 hail,指定一个数据库 haildb 给 hail

mysql -u root -p
password
use mysql;
insert into user(host,user,password) values('localhost','hail',password('hail'));
flush privileges;
create database haildb;
grant all privileges on haildb.* to hail@localhost identified by 'hail';
flush privileges;
如果想指定部分权限给用户

grant select,update on haildb.* to hail@localhost identified by 'hail';
flush privileges;
删除用户

delete from user where user='hail' and host='localhost';
flush privileges;
删除用户数据库

drop database haildb;
修改指定用户密码

update user set password=password('new_password') where user='hail' and host='localhost';
flush privileges;



1.远程登录mysql
mysql -h ip -u root -p 密码


2.创建用户
格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by “密码”;
例1:增加一个test1用户,密码为123456,可以在任何主机上登录,并对所有数据库有查询,增加,修改和删除的功能。需要在mysql的root用户下进行
mysql>grant select,insert,update,delete on *.* to test1@”%” identified by “123456″;
mysql>flush privileges;
例2:增加一个test2用户,密码为123456,只能在192.168.2.12上登录,并对数据库student有查询,增加,修改和删除的功能。需要在mysql的root用户下进行
mysql>grant select,insert,update,delete on student.* to test2@192.168.2.12 identified by “123456″;
mysql>flush privileges;
例3:授权用户test3拥有数据库student的所有权限
mysql>grant all privileges on student.* to test3@localhost identified by ’123456′;
mysql>flush privileges;
3.修改用户密码
mysql>update mysql.user set password=password(’123456′) where User=’test1′ and Host=’localhost’;
mysql>flush privileges;
4.删除用户
mysql>delete from user where user=’test2′ and host=’localhost’;
mysql>flush privileges;
5.删除数据库和删除表
mysql>drop database 数据库名;
mysql>drop table 表名;
6.删除账户及权限
drop user 用户名@’%’
drop user 用户名@localhost
**************************************************************************************
grant 详细解析如下:
**************************************************************************************
MySQL 赋予用户权限命令的简单格式可概括为:
grant 权限 on 数据库对象 to 用户


一、grant 普通数据用户,查询、插入、更新、删除 数据库中所有表数据的权利。
grant select on testdb.* to common_user@’%’
grant insert on testdb.* to common_user@’%’
grant update on testdb.* to common_user@’%’
grant delete on testdb.* to common_user@’%’
或者,用一条 MySQL 命令来替代:
grant select, insert, update, delete on testdb.* to common_user@’%’


二、grant 数据库开发人员,创建表、索引、视图、存储过程、函数。。。等权限。
grant 创建、修改、删除 MySQL 数据表结构权限。
grant create on testdb.* to developer@’192.168.0.%’;
grant alter on testdb.* to developer@’192.168.0.%’;
grant drop on testdb.* to developer@’192.168.0.%’;
grant 操作 MySQL 外键权限。
grant references on testdb.* to developer@’192.168.0.%’;
grant 操作 MySQL 临时表权限。
grant create temporary tables on testdb.* to developer@’192.168.0.%’;
grant 操作 MySQL 索引权限。
grant index on testdb.* to developer@’192.168.0.%’;
grant 操作 MySQL 视图、查看视图源代码 权限。
grant create view on testdb.* to developer@’192.168.0.%’;
grant show view on testdb.* to developer@’192.168.0.%’;
grant 操作 MySQL 存储过程、函数 权限。
grant create routine on testdb.* to developer@’192.168.0.%’; — now, can show procedure status
grant alter routine on testdb.* to developer@’192.168.0.%’; — now, you can drop a procedure
grant execute on testdb.* to developer@’192.168.0.%’;


三、grant 普通 DBA 管理某个 MySQL 数据库的权限。
grant all privileges on testdb to dba@’localhost’
其中,关键字 “privileges” 可以省略。


四、grant 高级 DBA 管理 MySQL 中所有数据库的权限。
grant all on *.* to dba@’localhost’


五、MySQL grant 权限,分别可以作用在多个层次上。
1. grant 作用在整个 MySQL 服务器上:
grant select on *.* to dba@localhost; — dba 可以查询 MySQL 中所有数据库中的表。
grant all on *.* to dba@localhost; — dba 可以管理 MySQL 中的所有数据库


2. grant 作用在单个数据库上:
grant select on testdb.* to dba@localhost; — dba 可以查询 testdb 中的表。

3. grant 作用在单个数据表上:
grant select, insert, update, delete on testdb.orders to dba@localhost;

4. grant 作用在表中的列上:
grant select(id, se, rank) on testdb.apache_log to dba@localhost;

5. grant 作用在存储过程、函数上:
grant execute on procedure testdb.pr_add to ‘dba’@’localhost’
grant execute on function testdb.fn_add to ‘dba’@’localhost’

六、查看 MySQL 用户权限
查看当前用户(自己)权限:
show grants;
查看其他 MySQL 用户权限:
show grants for dba@localhost;


七、撤销已经赋予给 MySQL 用户权限的权限。
revoke 跟 grant 的语法差不多,只需要把关键字 “to” 换成 “from” 即可:
grant all on *.* to dba@localhost;
revoke all on *.* from dba@localhost;


八、MySQL grant、revoke 用户权限注意事项
1. grant, revoke 用户权限后,该用户只有重新连接 MySQL 数据库,权限才能生效。
2. 如果想让授权的用户,也可以将这些权限 grant 给其他用户,需要选项 “grant option“
grant select on testdb.* to dba@localhost with grant option;
这个特性一般用不到。实际中,数据库权限最好由 DBA 来统一管理。


Category: Post
You can follow any responses to this entry via RSS.
Comments are currently closed, but you can trackback from your own site.
=========================================================================
1.创建用户并授权
grant语句的语法:
grant privileges (columns) on what to user identified by “password” with grant option
要使用该句型,需确定字段有:
privileges 权限指定符权限允许的操作
alter 修改表和索引
create 创建数据库和表
delete 删除表中已有的记录
drop 抛弃(删除)数据库和表
index 创建或抛弃索引
insert 向表中插入新行
reference 未用
select 检索表中的记录
update 修改现存表记录
file 读或写服务器上的文件
process 查看服务器中执行的线程信息或杀死线程
reload 重载授权表或清空日志、主机缓存或表缓存。
shutdown 关闭服务器
all 所有;
all privileges同义词
usage 特殊的“无权限”权限
以上权限分三组:

第一组:适用于数据库、表和列如:alter create delete drop index insert select update

第二组:数管理权限 它们允许用户影响服务器的操作 需严格地授权 如:file process reload shut*

第三组:权限特殊 all意味着“所有权限” uasge意味着无权限,即创建用户,但不授予权限

columns
权限运用的列(可选)并且你只能设置列特定的权限。如果命令有多于一个列,应该用逗号分开它们。

what
权限运用的级别。权限可以是全局,定数据库或特定表.

user
权限授予的用户,由一个用户名和主机名组成,许两个同名用户从不同地方连接.缺省:mysql用户password
赋予用户的口令(可选),如果你对用户没有指定identified by子句,该用户口令不变.
用identified by时,口令字符串用改用口令的字面含义,grant将为你编码口令.
注:set password使用password()函数

with grant option
用户可以授予权限通过grant语句授权给其它用户(可选)

实例讲解:
grant all on db_book.* to huaying@koowo.com identified by “yeelion”   只能在本地连接
grant all on db_book.* to huaying@vpn.koowo.com identified by “yeeliong”  允许从此域连接
grant all on db_book.* to huaying@% identified by “yeelion”   允许从任何主机连接 注:”%”字符起通配符作用,与like模式匹配的含义相同。
grant all on db_book.* to huaying@%.koowo.com identified by “yeelion”;  允许huaying从koowo.com域的任何主机连接
grant all on db_book.* to huaying@192.168.1.189 identified by “yeelion”
grant all on db_book.* to huaying@192.168.1.% identified by “yeelion”
grant all on db_book.* to huaying@192.168.1.0/17 identified by “yeelion”
允许从单IP 段IP或一子网IP登陆
注:有时 用户@IP 需用引号 如”huaying@192.168.1.0/17″

grant all on *.* to huaying@localhost identified by “yeelion” with grant option
添加超级用户huaying 可在本地登陆做任何操作.

grant reload on *.* to huaying@localhost identified by “yeelion” 只赋予reload权限
grant all on db_book to huaying@koowo.com indetified by “yeelion” 所有权限
grant select on db_book to huaying@% indetified by “yeelion” 只读权限
grant select,insert,delete,update on db_book to huaying@koowo.com indetified by “yeelion”

只有select,insert,delete,update的权限
grant select on db_book.storybook to huaying@localhost indetified by “yeelion” 只对表
grant update (name) on db_book.storybook to huaying@localhost 只对表的name列 密码不变
grant update (id,name,author) on db_book.storybook to huaying@localhost 只对表的多列
grant all on book.* to “”@koowo.com 允许koowo.com域中的所有用户使用库book
grant all on book.* to huaying@%.koowo.com indetified by “yeelion” with grant option
允许huaying对库book所有表的管理员授权.

2.撤权并删除用户
revoke的语法类似于grant语句
to用from取代,没有indetifed by和with grant option子句. 如下:

revoke privileges (columns) on what from user

user:必须匹配原来grant语句的你想撤权的用户的user部分。
privileges:不需匹配,可以用grant语句授权,然后用revoke语句只撤销部分权限。

revoke语句只删权限不删用户,撤销了所有权限后user表中用户记录保留,用户仍然可以连接服务器.

要完全删除一个用户必须用一条delete语句明确从user表中删除用户记录:
delete from user where user=”huaying”

flush privileges; 重载授权表
注:使用grant和revoke语句时,表自动重载,而你直接修改授权表时不是.

实例:
1.创建数据库
CREATE DATABASE  `fypay` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

2.为创建的数据库增加用户fypay
grant create,select,insert,update,delete,drop,alter on fypay.* to fypay@”%” identified by “testfpay”;

3.删除fypay用户
delete from user where user=”fypay”
drop user fypay@localhost

4.刷新数据库
flush privileges;

10 my_default.cnf文件信息

# Example MySQL config file for medium systems. 
# 
# This is for a system with little memory (32M - 64M) where MySQL plays 
# an important part, or systems up to 128M where MySQL is used together with 
# other programs (such as a web server) 
# 
# MySQL programs look for option files in a set of 
# locations which depend on the deployment platform. 
# You can copy this option file to one of those 
# locations. For information about these locations, see: 
# http://dev.mysql.com/doc/mysql/en/option-files.html 
# 
# In this file, you can use all long options that a program supports. 
# If you want to know which options a program supports, run the program 
# with the "--help" option. 
# The following options will be passed to all MySQL clients 
[client]
default-character-set=utf8
#password = your_password 
port = 3306 
socket = /opt/modules/mysql/data/mysqld.sock 
# Here follows entries for some specific programs 
# The MySQL server 
[mysqld]
character-set-server=utf8
init_connect='SET NAMES utf8
port = 3306 
socket = /opt/modules/mysql/data/mysqld.sock
basedir = /opt/modules/mysql 
datadir = /opt/modules/mysql/data
#最后加一句作用是使安装的mysql库不区分表大小写:
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
lower_case_table_names=1
#库
default-storage-engine=INNODB

skip-external-locking 
key_buffer_size = 16M 
max_allowed_packet = 1M 
table_open_cache = 64 
sort_buffer_size = 512K 
net_buffer_length = 8K 
read_buffer_size = 256K 
read_rnd_buffer_size = 512K 
myisam_sort_buffer_size = 8M 
character-set-server=utf8 
init_connect='SET NAMES utf8' 
# Don't listen on a TCP/IP port at all. This can be a security enhancement, 
# if all processes that need to connect to mysqld run on the same host. 
# All interaction with mysqld must be made via Unix sockets or named pipes. 
# Note that using this option without enabling named pipes on Windows 
# (via the "enable-named-pipe" option) will render mysqld useless! 
# 
#skip-networking

# Replication Master Server (default) 
# binary logging is required for replication 
log-bin=mysql-bin

# binary logging format - mixed recommended 
binlog_format=mixed

# required unique id between 1 and 2^32 - 1 
# defaults to 1 if master-host is not set 
# but will not function as a master if omitted 
server-id = 1

# Replication Slave (comment out master section to use this) 
# 
# To configure this host as a replication slave, you can choose between 
# two methods : 
# 
# 1) Use the CHANGE MASTER TO command (fully described in our manual) - 
# the syntax is: 
# 
# CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>, 
# MASTER_USER=<user>, MASTER_PASSWORD=<password> ; 
# 
# where you replace <host>, <user>, <password> by quoted strings and 
# <port> by the master's port number (3306 by default). 
# 
# Example: 
# 
# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306, 
# MASTER_USER='joe', MASTER_PASSWORD='secret'; 
# 
# OR 
# 
# 2) Set the variables below. However, in case you choose this method, then 
# start replication for the first time (even unsuccessfully, for example 
# if you mistyped the password in master-password and the slave fails to 
# connect), the slave will create a master.info file, and any later 
# change in this file to the variables' values below will be ignored and 
# overridden by the content of the master.info file, unless you shutdown 
# the slave server, delete master.info and restart the slaver server. 
# For that reason, you may want to leave the lines below untouched 
# (commented) and instead use CHANGE MASTER TO (see above) 
# 
# required unique id between 2 and 2^32 - 1 
# (and different from the master) 
# defaults to 2 if master-host is set 
# but will not function as a slave if omitted 
#server-id = 2 
# 
# The replication master for this slave - required 
#master-host = <hostname> 
# 
# The username the slave will use for authentication when connecting 
# to the master - required 
#master-user = <username> 
# 
# The password the slave will authenticate with when connecting to 
# the master - required 
#master-password = <password> 
# 
# The port the master is listening on. 
# optional - defaults to 3306 
#master-port = <port> 
# 
# binary logging - not required for slaves, but recommended 
#log-bin=mysql-bin

# Uncomment the following if you are using InnoDB tables 
#innodb_data_home_dir = /usr/local/mysql/data 
#innodb_data_file_path = ibdata1:10M:autoextend 
#innodb_log_group_home_dir = /usr/local/mysql/data 
# You can set .._buffer_pool_size up to 50 - 80 % 
# of RAM but beware of setting memory usage too high 
#innodb_buffer_pool_size = 16M 
#innodb_additional_mem_pool_size = 2M 
# Set .._log_file_size to 25 % of buffer pool size 
#innodb_log_file_size = 5M 
#innodb_log_buffer_size = 8M 
#innodb_flush_log_at_trx_commit = 1 
#innodb_lock_wait_timeout = 50

[mysqldump] 
quick 
max_allowed_packet = 16M

[mysql] 
no-auto-rehash 
# Remove the next comment character if you are not familiar with SQL 
#safe-updates 
default-character-set=utf8

[myisamchk] 
key_buffer_size = 20M 
sort_buffer_size = 20M 
read_buffer = 2M 
write_buffer = 2M

[mysqlhotcopy] 
interactive-timeout
  • 6
    点赞
  • 44
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
好的,下面是安装mysql5.6.51的步骤: 1. 下载mysql5.6.51的安装包,可以从官网或者镜像网站进行下载。 2. 解压安装包,使用以下命令进行解压: ``` tar zxvf mysql-5.6.51.tar.gz ``` 3. 安装必要的依赖,使用以下命令安装: ``` yum install -y cmake ncurses-devel ``` 4. 创建mysql用户和组,使用以下命令创建: ``` groupadd mysql useradd -r -g mysql -s /bin/false mysql ``` 5. 进入mysql安装目录,使用以下命令进行编译: ``` cd mysql-5.6.51 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DWITH_SSL=system \ -DWITH_ZLIB=system \ -DENABLED_LOCAL_INFILE=1 \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci ``` 6. 编译完成后,使用以下命令进行安装: ``` make && make install ``` 7. 初始化mysql数据库,使用以下命令进行初始化: ``` cd /usr/local/mysql ./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data ``` 8. 修改配置文件,使用以下命令进行修改: ``` cp support-files/my-default.cnf /etc/my.cnf ``` 在/etc/my.cnf文件中添加以下内容: ``` [mysqld] datadir=/usr/local/mysql/data socket=/usr/local/mysql/mysql.sock user=mysql ``` 9. 启动mysql服务,使用以下命令进行启动: ``` /usr/local/mysql/support-files/mysql.server start ``` 10. 测试mysql服务,使用以下命令进行测试: ``` /usr/local/mysql/bin/mysql -uroot -p ``` 输入初始密码(在初始化mysql数据库时生成的),进入mysql命令行后,即表示安装成功。 希望我的回答能够帮助到您,如有疑问请随时提出。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值