1、首先关闭linux的防火墙,执行命令
chkconfig iptables off
2、从mysql官网上下载自己mysql:https://dev.mysql.com/downloads/
3、下载后的mysql文件:mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz,将下载好的mysql压缩文件放置在linux的/usr/local文件夹下,解压该压缩文件
tar -zxvf mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
重命名文件夹:
mv mysql-5.6.43-linux-glibc2.12-x86_64 mysql
4、创建mysql用户组及用户
groupadd mysql //添加mysql组
useradd -r -g mysql mysql //添加用户
5、编辑/etc/my.cnf文件;
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
socket = /tmp/mysql.sock
character-set-server = utf8
skip-name-resolve
log-err = /usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mysql.pid
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
6、在mysql当前目录下设定目录的访问权限(注意后面的小点,表示当前目录)
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
7、初始化数据(在mysql/scripts下有个 mysql_install_db 可执行文件初始化数据库),进入mysql/scripts目录下,执行下面命令
./mysql_install_db --verbose --user=root --defaults-file=/etc/my.cnf --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql --pid-file=/usr/local/mysql/data/mysql.pid --tmpdir=/tmp
8、启动mysql,进入/usr/local/mysql/bin目录,执行下面命令
./mysqld_safe --defaults-file=/etc/my.cnf --socket=/tmp/mysql.sock --user=root &
注意,如果光标停留在屏幕上,表示启动成功,需要我们先关闭shell终端,再开启一个新的shell终端,不要执行退出操作。如果出现 mysql
9、设置开机启动,新开启shell中断后,进入mysql目录,执行下面命令
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
cp /usr/local/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 /usr/local/mysql/
重启linux
reboot
查看mysql状态
service mysqld status
10、添加远程访问权限
(1)、添加mysql命令
ln -s /usr/local/mysql/bin/mysql /usr/bin (mysql的安装路径)
(2)、更改访问权限
登录mysql,执行下面命令
mysql -uroot -p
密码为空直接回车,运行以下两条命令
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'duan' with grant option;
Flush privileges;
退出mysql
exit
重启linux,就完成了
reboot
注:本机访问mysql,root账户默认是没有密码的,端口号默认3306,如果需要修改root账户密码,在/usr/local/mysql/bin目录下,执行下面命令
./mysqladmin -h 127.0.0.1 -P3306 -uroot password 'duan'exit
查看mySQL是否启动成功:
1、 看看是否有mysqld_safe 和mysqld进程
ps -ef|grep mysqld
显示结果:
1)root 4052 29869 0 10:25 pts/0 00:00:00 grep mysqld
2)root 30905 1 0 10:14 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
3)mysql 31231 30905 1 10:14 pts/0 00:00:09 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/localhost.localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid --socket=/tmp/mysqld.sock --port=3306
2、如果已添加到系统服务中,可以service mysqld status
service mysqld status
显示结果:
SUCCESS! MySQL running (31231)