在linux环境安装mysql5.7

 

下载安装包

mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

 

进入mysql安装目录解压安装包

[root@c1 ~]# cd /usr/local/

[root@c1 ~]# cd /usr/local/

[root@c1 local]# tar -xzvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

创建软连接

ln -s mysql-5.7.18-linux-glibc2.5-x86_64 mysql

创建mysql用户组和mysql用户

[root@c1 local]# groupadd mysql

[root@c1 local]# useradd -r -g mysql -s /bin/false mysql

添加环境变量

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

创建数据目录

[root@c1 mysql]# mkdir data

进入mysql目录 设置权限

[root@c1 mysql]# chown -R mysql .

[root@c1 mysql]# chgrp -R mysql .

初始化数据库

[root@c1 mysql]# bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize —user=mysql

2017-04-22T03:35:46.881957Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2017-04-22T03:35:47.316012Z 0 [Warning] InnoDB: New log files created, LSN=45790

2017-04-22T03:35:47.416436Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2017-04-22T03:35:47.501745Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c61db9e6-270c-11e7-9df4-0800274f6f8e.

2017-04-22T03:35:47.503551Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2017-04-22T03:35:47.504380Z 1 [Note] A temporary password is generated for root@localhost: d762:DwgnS*l

 

记住临时root密码  

d762:DwgnS*l

由于我们安装mysql目录不是我们指定的安装目录我们需要修改/etc/my.cnf

指定basedir 和datadir 目录

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

 

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

 

 

修改为

 

[[mysqld]

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

socket=/usr/local/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

 

[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

 

[client]

socket=/usr/local/mysql/mysql.sock

port=3306

 

复制启动mysql服务脚本

[root@c1 mysql]# cp -a support-files/mysql.server  /etc/init.d/mysqld

启动服务

[root@c1 mysql]# /etc/init.d/mysqld start

Starting MySQL.                                            [  OK  ]

 

mysql 控制台 登录

[root@c1 bin]# ./mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.7.18

 

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> set passord =password('123456');

ERROR 1193 (HY000): Unknown system variable 'passord'

mysql> set password=password('123456');

Query OK, 0 rows affected, 1 warning (0.00 sec)

 

 

修改密码 

更改可以使用root账号远程访问数据库

[root@c1 bin]# ./mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.7.18

 

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> set passord =password('123456');

ERROR 1193 (HY000): Unknown system variable 'passord'

mysql> set password=password('123456');

Query OK, 0 rows affected, 1 warning (0.00 sec)

 

 

刷新权限

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

 

最后添加启动服务

chkconfig —level 35 mysqld on 

 

 

 

 

 

 

 

 

 

 

猜你喜欢

转载自qq466862016.iteye.com/blog/2370769