首页 > 数据库技术 > 详细

Linux服务安装mysql

时间:2019-05-05 20:19:18      阅读:138      评论:0      收藏:0      [点我收藏+]

1、首先关闭linux防火墙,执行命令

Centos 6 :chkconfig iptables off
?
Centos 7 : chkconfig firewalld off

2、官网下载合适的mysql版本

https://dev.mysql.com/downloads/mysql/5.6.html#downloads

3、解压文件

tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz

4、把解压文件移动指定文件夹内

mv mysql-5.6.33-linux-glibc2.5-x86_64/* /opt/mysql

 

5、创建mysql用户组及用户
groupadd mysql
?
useradd -r -g mysql mysql

错误信息 FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db: Data::Dumper 解决方法是安装autoconf库 执行命令:yum -y install autoconf

6、进入到mysql目录,执行添加MySQL配置的操作
cp support-files/my-medium.cnf /etc/my.cnf
或:
cp support-files/my-default.cnf /etc/my.cnf
是否覆盖?按y 回车
7、编辑/etc/my.cnf文件
vi /etc/my.cnf

在my.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 = /opt/mysql
datadir = /opt/mysql/data
port = 3306
# server_id = .....
socket = /tmp/mysql.sock
character-set-server = utf8
skip-name-resolve
log-err = /opt/mysql/data/error.log
pid-file = /opt/mysql/data/mysql.pid
?
# 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
8、在mysql当前目录下设定目录的访问权限(注意后面的小点,表示当前目录)
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
9、初始化数据(在mysql/bin或者mysql/scripts下有个 mysql_install_db 可执行文件初始化数据库),进入mysql/bin或者mysql/scripts目录下,执行下面命令
./mysql_install_db --verbose --user=root --defaults-file=/etc/my.cnf --datadir=/opt/mysql/data --basedir=/opt/mysql --pid-file=/opt/mysql/data/mysql.pid --tmpdir=/tmp
10、启动mysql,进入/usr/local/mysql/bin目录,执行下面命令
./mysqld_safe --defaults-file=/etc/my.cnf --socket=/tmp/mysql.sock --user=root &
注意,如果光标停留在屏幕上,表示启动成功,需要我们先关闭shell终端,再开启一个新的shell终端,不要执行退出操作。如果出现 mysql
11、设置开机启动,新开启shell中断后,进入mysql目录,执行下面命令
cp /opt/mysql/support-files/mysql.server /etc/init.d/mysqld
cp /opt/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql
?
chmod 700 /etc/init.d/mysql
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
chown mysql:mysql -R /opt/mysql/

重启linux

reboot

查看mysql状态

service mysqld status
12、添加远程访问权限

(1)、添加MySQL命令

ln  -s /opt/mysql/bin/mysql  /usr/bin  (mysql的安装路径)

(2)、更改访问权限

登录mysql,执行下面命令
mysql -uroot -p
密码为空直接回车,运行以下两条命令
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456‘ with grant option;
Flush privileges;

退出mysql

exit

重启linux,就完成了

reboot

Linux服务安装mysql

原文:https://www.cnblogs.com/mengshuo/p/10815751.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!