找回密码
 立即注册
Qt开源社区 门户 查看内容

linux-Mysql安装

2019-4-15 22:18| 发布者: admin| 查看: 823| 评论: 0

摘要: 1、目录约定安装文件下载目录:/data/softwareMysql目录安装位置:/usr/local/mysql数据库保存位置:/data/mysql日志保存位置:/data/log/mysql2、下载mysql在官网:http://dev.mysql.com/downloads/mysql/中,选择 ...
1、目录约定

安装文件下载目录:/data/software

Mysql目录安装位置:/usr/local/mysql

数据库保存位置:/data/mysql

日志保存位置:/data/log/mysql

2、下载mysql

在官网:http://dev.mysql.com/downloads/mysql/ 中,选择需要的版本并下载:我们以mysql-5.7.17为例



执行如下命名:

# mkdir -p /data/software

# mkdir -p /usr/local/mysql

# cd /data/software

--下载安装包

--建议:在windows上使用迅雷下载,速度很快(我的是1M/s),然后用工具(Xftp)上传到 /data/software目录下;

# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

3、解压压缩包到目标位置

#cd /data/software

--解压压缩包

# tar -xzvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

--移动并修改文件名

# mv mysql-5.7.17-linux-glibc2.5-x86_64/*  /usr/local/mysql

4、创建数据仓库目录

--创建/data/mysql 数据仓库目录

# mkdir /data/mysql       

# ls /data/



5、新建mysql用户、组及目录

  1. 暴力删除mysql用户:删除语法: userdel -r -f mysql(如果没有,会提示你mysql不存在,不用在意);

  2. 添加分组:添加语法: groupadd mysql

  3. 新建msyql用户禁止登录shell:useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql   

6、改变目录所有者

# cd /usr/local/mysql

# pwd



# chown -R mysql .

# chgrp -R mysql .

# chown -R mysql /data/mysql

7、配置参数
# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql



此处需要注意记录生成的临时密码,如上文结尾处的:#8n&uHEzr03h

# bin/mysql_ssl_rsa_setup  --datadir=/data/mysql

8、修改系统配置文件

# cd /usr/local/mysql/support-files



# cp my-default.cnf /etc/my.cnf

# cp mysql.server /etc/init.d/mysql

# vim /etc/init.d/mysql

修改以下内容:



9、启动mysql

# /etc/init.d/mysql start

--登陆

# cd /usr/local/mysql/bin

# mysql -hlocalhost -uroot -p

--输入第7步生成的临时密码:#8n&uHEzr03h

如果登录不上或者忘记:

1.  修改MySQL的登录设置:
# vim /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables
例如:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
保存并且退出vi。

2.重新启动mysqld
# service mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]

3.登录并修改MySQL的root密码
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 3.23.56
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> USE mysql ;
Database changed
mysql>update user set authentication_string = password("new-password") where user="root" ;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0
mysql> flush privileges ;
Query OK, 0 rows affected (0.01 sec)
mysql> quit

4.将MySQL的登录设置修改回来
# vim /etc/my.cnf
将刚才在[mysqld]的段中加上的skip-grant-tables删除
保存并且退出vim

5.重新启动mysqld
# service mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]

--修改密码

mysql> set password=password('root');

--设置root账户的host地址(修改了才可以远程连接)

mysql>grant all privileges on *.* to 'root'@'%' identified by 'root';

mysql>flush privileges;

--查看表

mysql> use mysql;

mysql> select host,user from user;

--这里就可以使用远程连接测试了;



10、添加系统路径

# vim /etc/profile

添加:export PATH=/usr/local/mysql/bin:$PATH

如下:



# source /etc/profile

11、配置mysql自动启动

# chmod 755 /etc/init.d/mysql

# chkconfig --add mysql

# chkconfig --level 345 mysql on


附:my.cnf 配置
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]
#改善远程连接慢的问题
skip-name-resolve
#
character-set-server=utf8
collation-server=utf8_general_ci
connect_timeout=60
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

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

# 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

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


----------------------------------------------------------------------------------------------------------------------
我们尊重原创,也注重分享,文章来源于微信公众号:晓海随笔,建议关注公众号查看原文。如若侵权请联系qter@qter.org。
----------------------------------------------------------------------------------------------------------------------

鲜花

握手

雷人

路过

鸡蛋

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了