linux 安装mysql 5.7

下载  jar  上传
# tar -xzvf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
# mv mysql-5.7.20-linux-glibc2.12-x86_64  /usr/local/mysql
#添加用户组
groupadd mysql  #若是报错存在就,就不用添加了
#添加用户mysql 到用户组mysql
useradd -g mysql mysql   #若是报错存在就,就不用添加了
# mkdir data
# chown -R mysql:mysql ./
# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql-5.7.20/ --datadir=/usr/local/mysql-5.7.20/data/

# chown -R root .mysql

# chown -R mysql datalinux

# cp support-files/mysql.server /etc/init.d/mysqld
# chmod 755 /etc/init.d/mysqld
cp /usr/local/mysql/bin/my_print_defaults /usr/bin/
#修改启动脚本
[root@instance_4dbde0 mysql]# vi /etc/init.d/mysqld
#修改项:
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data
port=3306
#启动服务
[root@instance_4dbde0 mysql]# service mysqld start


(若是启动报错,就看错误日志,错误日志的路径在my.cfg 中error.log)
(有添加软链接、

从报错上来看,是因为缺乏了mysql.plugin表所致的,不过如今连启动都启动不了,怎样建立表呢?因此确定是其余缘由致使的,于时继续网上找继续试,最后找到了这个处理方法,进入mysql安装后的目录scripts执行如下语句:sql

 

[root@localhost bin]# ./mysql_install_db --user=mysql --basedir=/home/mysql5627 --datadir=/usr/mysqldata服务器

)
#加入环境变量,编辑 /etc/profile,这样能够在任何地方用mysql命令了
[root@instance_4dbde0 mysql]# vi /etc/profile
#添加mysql路径
export PATH=$PATH:/usr/local/mysql-5.7.20/bin
#刷新当即生效
[root@instance_4dbde0 mysql-5.7.20]# source /etc/profile

 

====================================================================================socket

下面是mysql 5.6 二进制文件安装tcp

在这个 /data/mysql 路径下编码

tar -zxvf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
--链接路径
cd  /usr/local 
--执行
ln -s /data/mysql mysql

-s /bin/false参数指定mysql用户仅拥有全部权,而没有登陆权限.net

--建立用户组
groupadd mysql 
--建立用户
useradd -r -g mysql -s /bin/false mysql

就是给上面建立的用户分配权限rest

cd /data/mysql
chown -R mysql:mysql ./

当前所在路径是 /data/mysql. 日志

./mysql_install_db  --datadir=/data/mysql/data --basedir=/data/mysql --user=mysql

若是出错,报“/usr/bin/perl: bad interpreter: No such file or directory”,能够先安装perl脚本,命令以下:

yum -y install perl perl-devel
yum install -y perl-Data-Dumper

完成后再执行上面初始化mysql脚本。。。。

默认配置文件所在位置 /etc/my.cnf,执行完步骤6的时候会默认生成一个配置文件

vi /etc/my.cnf
[mysqld]
datadir=/data/mysql-5.6/data
socket=/data/mysql-5.6/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

# 指定编码
character-set-server=utf8
collation-server=utf8_general_ci

user=mysql

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log   #能够改成其余路径,确保路径存在,而且mysql用户组有写入权限
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

#指定客户端链接mysql时的socket通讯文件路径
[client]
socket=/usr/local/mysql/mysql.sock
default-character-set=utf8

若是没有错误则启动成功

./support-files/mysql.server start

将mysql进程放入系统进程中,命令以下:

cp support-files/mysql.server /etc/init.d/mysqld

重启mysql

service mysqld restart
#第一次登录没有密码,直接回车 在MySQL 的安装路径软链接 /usr/local/mysql/bin   下面执行
./mysql -u root -p

若是有报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'

[root@localhost bin]# ./mysql -u root -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

链接localhost一般经过一个Unix域套接字文件进行,通常是/tmp/mysql.sock。若是套接字文件被删除了,本地客户就不能链接。这可能发生在你的系统运行一个cron任务删除了/tmp下的临时文件。

若是你由于丢失套接字文件而不能链接,你能够简单地经过重启服务器从新建立获得它。由于服务器在启动时从新建立它。
就这样执行

./mysql -uroot -h 127.0.0.1 -p 

修改root密码

#newpass就是你的新密码
mysql> use mysql;

mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
##远程访问权限
mysql> update user set host = '%' where user = 'root'; 

mysql> FLUSH PRIVILEGES;

若是报错,Warning: Using a password on the command line interface can be insecure.

在/etc/my.cnf 中加上

[mysqldump]

user=your_backup_user_name

password=your_backup_password

至此mysql安装阶段完成了。。

开启3306 端口

 sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent

命令含义: 
zone #做用域 
add-port=80/tcp #添加端口,格式为:端口/通信协议 
permanent #永久生效,没有此参数重启后失效

Step2:重启防火墙

[sunwei@test2 ~]$ sudo firewall-cmd --reload

相关文章
相关标签/搜索