mysql安装教程

1、下载

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz

2、安装

tar -xzf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz

mv mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/mysql

3、创建mysql用户组和mysql用户

groupadd mysql

useradd -s /sbin/nologin -M -g mysql mysql

4、设置mysql目录访问权限,用户组

mkdir -p /data/mysql

mkdir -p /data/mysql/{data,logs,tmp}

chown -R mysql.mysql /usr/local/mysql

chown -R mysql.mysql /data/mysql/

5、初始化mysql

/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/data/

报错:

解决方法: yum install libaio* -y

Root账号临时密码

6、配置my.cnf

vim /etc/my.cnf

[client]

socket=/data/mysql/tmp/mysql.sock

default-character-set = utf8

 

[mysqld]

user = mysql

port = 3306

character_set_server=utf8

basedir=/usr/local/mysql

datadir=/data/mysql/data

log-error=/data/mysql/logs/mysqld.log

pid-file=/data/mysql/tmp/mysqld.pid

socket=/data/mysql/tmp/mysql.sock

 

lower_case_table_names = 1

max_connections=5000

sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

 

symbolic-links=0

 

long_query_time = 1

slow_query_log = ON

slow_query_log_file = /data/mysql/logs/mysqld_slow.log

 

default-storage-engine=INNODB

 

[mysqld_safe]

log-error=/data/mysql/logs/mysqld.log

pid-file=/data/mysql/tmp/mysqld.pid

7、配置mysql自动启动

touch /data/mysql/logs/mysqld.log

touch /data/mysql/tmp/mysql.sock

touch /data/mysql/tmp/mysqld.pid

chown -R mysql.mysql /data/mysql/

 

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

chmod +x /etc/rc.d/init.d/mysqld

加入启动项:

chkconfig --add mysqld

chkconfig mysqld on

启动:

/etc/init.d/mysqld start

8、配置mysql到环境变量

vim /etc/profile

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

export PATH

source /etc/profile

9、修改密码

忘记密码:

skip-grant-tables

 

mysql>alter user 'root'@'localhost' identified by '123456';

mysql>flush privileges;

mysql>quit;

10、添加远程访问权限

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

mysql> grant all privileges on *.* to root@'%' identified by 'root';

  //执行之后如果出现下面ERROR,可不用理会

  ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'

mysql> flush privileges;

mysql> use mysql;

mysql> update user set host='%' where user = 'root';

mysql> flush privileges;

修改密码:

mysql> update user set authentication_string=password('123456') where user='root' and Host='localhost';

查看mysql.user 信息

select Host,User,authentication_string from user;

11、开启bin-log日志

my.cnf加入如下内容

server-id=1

log-bin=mysql-bin

max_binlog_size=100M   #bin-log日志大小

expire_logs_days=10       #bin-log保存时间

 

posted @ 2021-09-08 11:43  钱哥的博客  阅读(76)  评论(0编辑  收藏  举报