{channel.title!channel.name} - 楚淮公司周东林

centos7用tar安装包安装mysql

用 yum 安装 mysql 虽然方便但是目录不好自己指定很麻烦,从mysql网站下载了 mysql-5.7.22-el7-x86_64.tar.gz 自己手动安装试试。


1#卸载 mariadb (如果不是最小安装 centos7 可能自带 mariadb)

[root@zhoudl ~]#yum remove mariadb mariadb-server

​2#检查是否存在mysql用户和组,没有要新建

3#检查mysql组和用户是否存在
[root@zhoudl ~]# cat /etc/group | grep mysql
[root@zhoudl ~]#  cat /etc/passwd | grep mysql

​#如果没有创建mysql用户组

[root@zhoudl ~]# groupadd mysql
#创建一个用户名为mysql的用户并加入mysql用户组
[root@zhoudl
~]# useradd -g mysql mysql

#设置密码

[root@zhoudl ~]#passwd mysql

4#配置 /etc/my.cnf

[mysqld]
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/data/mysql.sock
# 允许最大连接数
max_connections=200
[mysqld_safe]
log-error=/var/log/mysql/mysql.log
pid-file=/var/run/mysql/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
socket=/usr/local/mysql/data/mysql.sock
[client]
default-character-set=utf8
socket=/usr/local/mysql/data/mysql.sock

5#安装初始化数据库

[root@zhoudl mysql]# bin/mysql_install_db  --basedir=/usr/local/mysql-5.7.22/ --datadir=/usr/local/mysql-5.7.22/data/
2018-09-26 15:16:27 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2018-09-26 15:16:29 [WARNING] The bootstrap log isn't empty:
2018-09-26 15:16:29 [WARNING] 2018-09-26T07:16:27.716120Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

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

6#更改文件所属用户组

[root@zhoudl /]# chown -R mysql:mysql /usr/local/mysql/

[root@zhoudl mysql]# chown 777 /etc/my.cnf
[root@zhoudl mysql]#
chmod +x /etc/init.d/mysqld

[root@zhoudl mysql]# /etc/init.d/mysqld restart           
 ERROR! MySQL server PID file could not be found!
Starting MySQL. SUCCESS!
[root@zhoudl mysql]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!

[root@zhoudl mysql]# ln -s /usr/local/mysql/bin/mysql   /usr/bin/mysql

#设置为服务

 

[root@zhoudl ~]# chkconfig --level 35 mysqld on
[root@zhoudl ~]# chkconfig --list mysqld
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.
      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@zhoudl ~]# chmod +x /etc/rc.d/init.d/mysqld
[root@zhoudl ~]# chkconfig --add mysqld
[root@zhoudl ~]# chkconfig --list mysqld
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.
      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@zhoudl ~]# service mysqld status
 SUCCESS! MySQL running (5098)
 
#设置环境变量
[root@zhoudl /]# vim /etc/profile
添加如下一行:
export PATH=$PATH://usr/local/mysql/bin
#查看数据库密码
[root@zhoudl ~]# cat /root/.mysql_secret 
# Password set for user 'root@localhost' at 2018-09-26 16:17:35
.6G>VLvjgMAs
#登陆数据库
[root@zhoudl /]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.22
Copyright (c) 2000, 2018, 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>
#重新设置本机密码
mysql> set password for root@'localhost'=password('123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
#远程登陆密码
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'jschrj' WITH GRANT OPTION
    -> ;
Query OK, 0 rows affected, 1 warning (0.00 sec)

下面自己安装 Navicat for MySQL 客户端在桌面环境慢慢玩吧。

注意点:1.文件夹目录权限。2.用 yum 安装第一次登陆不需要密码,用 tar 安装密码藏在 /root/.mysql_secret  目录下。3.my.cnf 的设置。4.如果原来安装过 mariadb 有些目录要删干净比如日志目录。5.要心细。6.经验最重要

 

 


浏览.发表于:2018-09-26 15:16:53