Linux安装MYSQL

来源:互联网 发布:mac强制卸载程序 编辑:程序博客网 时间:2024/06/07 06:26

1.1下载MYSQL

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz

1.2解压文件

tar -zxvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

1.3重命名

mv mysql-5.7.19-linux-glibc2.12-x86_64/ /usr/local/mysql

2.1创建文件夹(存储mysql数据)

mkdir -p /data/mysql

2.2进入mysql目录

cd /usr/local/mysql

2.3添加用户组

groupadd mysql

2.4添加用户到组

useradd -g mysql mysql

2.5改变目录属有者(下面的所有操作都在/usr/local/mysql中执行)

chown -R mysql .chgrp -R mysql .chown -R mysql /data/mysql

3.1安装命令,执行解压包bin下的mysqld命令。此时会生成临时密码,记得记下来(9KpthxNq3a/a)

./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

3.2生成SSL连接时使用的文件(可以省略)

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

4.0修改系统配置文件,将support-files文件夹下的my-default.cnf,mysql.server复制到/etc和/etc/init.d下(最新版已经没有my-default.cnf文件,可以自己按格式建立一个)
4.1MYSQL5.7.19没有my-default.cnf自己新建

vim /support-files/my-default.cnf

复制下面内容···

# For advice on how to change settings please see# http://dev.mysql.com/doc/refman/5.6/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]# 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 = .....# datadir = .....# port = .....# server_id = .....# socket = .....basedir = /usr/local/mysqldatadir = /data/mysql# 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

4.2复制文件并替换

cp support-files/my-default.cnf /etc/my.cnf     ##mysql配置文件cp support-files/mysql.server /etc/init.d/mysql MYSQL启动命令文件

4.3修改/etc/init.d/mysql文件

vim /etc/init.d/mysql

添加basedir和datadir(与3.1步骤上相同即可)

basedir=/usr/local/mysqldatadir=/data/mysql

5.启动服务

./bin/mysqld_safe --user=mysql &#(可能会报错不管)

登录MYSQL

./bin/mysql -uroot -p

修改密码

set password=password('root'); 

修改登录权限

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

刷新权限

flush privileges;

查询

use mysql;select host,user from user;

6.添加系统路径

vim /etc/profile

添加内容

export PATH=/usr/local/mysql:$PATH

7.配置mysql自动启动
/etc/init.d/mysql可执行权限

chmod 755 /etc/init.d/mysql     OR chmod a+x /etc/init.d/mysqlchkconfig --add mysqlchkconfig --level 345 mysql on

8.创建软连接(就可以在任意位置输入mysql -uroot -p命令)

ln -s /usr/local/mysql/bin/mysql /usr/bin

9.删除开机启动

chkconfig --del mysqld
原创粉丝点击