*注:本文安装的是mysql5.6的版本,反复安装三遍总结下来的详细安装步骤。
tar -xzf mysql-5.6.45-linux-glibc2.12-x86_64.tar.gz
常用的解压命令:
1、*.tar 用 tar –xvf 解压
2、*.gz 用 gzip -d或者gunzip 解压
3、*.tar.gz和*.tgz 用 tar –xzf 解压
4、*.bz2 用 bzip2 -d或者用bunzip2 解压
5、*.tar.bz2用tar –xjf 解压
6、*.Z 用 uncompress 解压
7、*.tar.Z 用tar –xZf 解压
8、*.rar 用 unrar e解压
9、*.zip 用 unzip 解压
mv mysql-5.6.45-linux-glibc2.12-x86_64 /usr/local/mysql
mkdir /data/mysql
这里添加的 mysql 用户和用户组是稍后用来给 MySQL 安装目录分配权限用的,所以并不需要设定密码,因为这个用户是不能直接登录 Linux 系统的。
4.1 添加mysql用户组
groupadd mysql
4.2. 添加mysql用户,同时指定mysql用户的初始组是mysql组
useradd -g mysql mysql
cd /usr/local/mysql/
chown -R mysql .
chgrp -R mysql .
修改data/mysql目录权限为MySQL用户
chown -R mysql /data/mysql
./scripts/mysql_install_db --user=mysql
7.1初始化报错(不报错请忽略):解决方法是安装autoconf库
执行命令:
yum -y install autoconf
yum -y install perl perl-devel
然后再次执行初始化数据库的命令即可。
chown -R root:root ./
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
11.1进入配置目录
cd /usr/local/mysql/support-files/
11.2复制并修改文件名到指定目录
1)把mysql配置文件放到指定目录
cp my-default.cnf /etc/my.cnf
如果不存在my-default.cnf文件或不清楚my.cnf的配置,可以参考博主的my.cnf文件配置,在本博客底部。
2)启动脚本放到开机初始化目录
cp mysql.server /etc/init.d/mysql
vim /etc/init.d/mysql
添加如下配置:
basedir=/usr/local/mysql
datadir=/data/mysql
service mysql start
ps -ef|grep mysql
./bin/mysqladmin -u root password '密码'
修改报错(不报错的可以略过):找不到mysql.sock文件
处理: 1.使用kill命令杀掉mysql的进程
2.然后重新启动mysql服务
3.再次查看/tmp目录,
此时已经生成mysql.sock文件,问题解决
mysql -hlocalhost -uroot -p
**a)使用%代替IP地址,代表所有ip都可以远程连接**
mysql> grant all privileges on *.* to root@'%' identified by 'root';
*说明一下:我的用户名,密码都是root,大家要注意改成自己的用户密码
**b)刷新,使配置生效**
mysql>flush privileges;
mysql> use mysql;
mysql> select host,user from user;
退出mysql命令窗口
mysql> exit
至此,就可以使用Navicat等客户端工具连接mysql数据库了,如果是阿里云服务器,要新建3306端口。
a)编辑profile文件
vim /etc/profile
添加配置export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile
chmod 755 /etc/init.d/mysql
chkconfig --add mysql
chkconfig --level 345 mysql on
至此,正式完成mysql的安装配置。
#service mysql status
–停止mysql
#service mysql stop
–启动mysql
#service mysql start
more /etc/passwd | grep mysql
more /etc/shadow | grep mysql
userdel mysql
#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]
# 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
character-set-server=utf8
collation-server=utf8_bin
init-connect='SET NAMES utf8'
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
bind-address = 0.0.0.0
server_id = 22206
socket = /data/mysql/mysql.sock
binlog_format = statement
# 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
log_bin_trust_function_creators = on
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
。
。
。
*觉得有用可以关注博主哦,如果再不能相遇,祝你早午晚都安。。。