longxd

导航

 

二进制安装mysql

1,下载安装包,使用国内站点速度会比较快,如清华站点https://mirrors.tuna.tsinghua.edu.cn

登陆linux系统后,使用wget 进行下载mysql安装包。

#wget https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.25-el7-x86_64.tar.gz

 

2,创建目录,把mysql安装包放入制定目录。

#cd /usr/local

# mkdir mysql

# mv mysql-5.7.25-el7-x86_64.tar.gz mysql/

 

 

 

3,解压安装包

# tar -zxvf mysql-5.7.25-el7-x86_64.tar.gz

查看解压后的文件:

 

 

4,创建用户和组。

# groupadd mysql

# useradd -g mysql mysql

 

5,/usr/local/mysql/mysql-5.7.25-el7-x86_64下创建datalog目录(如果有的话就不需要创建)

#cd /usr/local/mysql/mysql-5.7.25-el7-x86_64

#mkdir log

#mkdir data 

6,设置配置文件 /etc/my.cnf

[client]

port = 3306

socket = /tmp/mysql.sock

default-character-set=utf8

 

[mysqld]

user=mysql

port = 3306

server_id = 1

socket=/tmp/mysql.sock

basedir =/usr/local/mysql/mysql-5.7.25-el7-x86_64

datadir =/usr/local/mysql/mysql-5.7.25-el7-x86_64/data

pid-file=/usr/local/mysql/mysql-5.7.25-el7-x86_64/data/mysqld.pid

log-error=/usr/local/mysql/mysql-5.7.25-el7-x86_64/log/mysql-error.log

character_set_server=utf8

max_connections=1000

 

 

7,更改mysql安装文件的权限。

[root@192 mysql]# pwd

/usr/local/mysql

[root@192 mysql]# chown -R mysql:mysql mysql-5.7.25-el7-x86_64

创建log文件

# touch mysql-error.log

# chown 776 mysql-error.log

# chown mysql:mysql mysql-error.log

创建socketfile文件。

# mkdir socketfile

# chown -R mysql:mysql socketfile

 

8,初始化数据库

#cd /usr/local/mysql/mysql-5.7.25-el7-x86_64/bin

./mysqld --initialize --user=mysql

mysql-error.log文件中查看初始密码。

#cd /usr/local/mysql/mysql-5.7.25-el7-x86_64/log

# cat mysql-error.log

 

9,配置环境变量,编辑/etc/profile文件,添加Mysql查找路径。

#vi /etc/profile

 

设置mysql service服务

#cd /usr/local/mysql/mysql-5.7.25-el7-x86_64/support-files

# cp mysql.server /etc/init.d/mysql.server

 

启动mysql服务:

#service mysql.server start

发现报错,根据报错内容创建/log/mariadb/mariadb.log/data/mysqld.pid

通常手动编译安装会遇到依赖问题,如果有以下这种错误:

 

解决方法如下:

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

yum localinstall mysql57-community-release-el7-11.noarch.rpm

yum install mysql-community-client.x86_64 mysql-community-server.x86_64

 

重启mysql服务。

# service mysql.server restart

 

10,查看mysql临时密码,使用临时密码登陆mysql

#cd /usr/local/mysql/mysql-5.7.25-el7-x86_64/log

# cat mysql-error.log | grep 'root@localhost:'

# cat mysql-error.log | grep 'root@localhost:'|awk '{print $NF}'

 

 

11,更改root密码,和创建新用户及设置新用户的权限。

mysql> SET PASSWORD = PASSWORD('qwe123');

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

 

 

创建用户配置登录:

mysql> CREATE USER 'test'@'%' IDENTIFIED BY 'qwe123';

Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL  ON *.* TO 'test'@'%';

Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

 

 

修改密码:

mysql> update mysql.user set authentication_string=password('123456') where user='root';

配置文件:/etc/my.cnf

 

posted on 2019-04-18 10:50  longxd  阅读(174)  评论(0编辑  收藏  举报