mysql5.7.28tar包安装

mysql给root开启远程访问权限

mysql5.7.28tar包安装

下载数据库tar包,地址:https://dev.mysql.com/downloads/mysql/5.7.html
在这里插入图片描述

下载前先查看linxu系统的位数

如何查看linux是32位还是64位
使用命令 getconf LONG_BIT
如果返回的是32,那么就是32位
如果返回的是64,那么就是64位

#卸载系统自带的Mariadb

[root@ ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64

#删除etc目录下的my.cnf文件

[root@ ~]# rm -rf /etc/my.cnf

检查mysql是否存在

[root@ ~]# rpm -qa | grep mysql
[root@ ~]#

检查mysql组和用户是否存在,如无创建
linux如何查看所有的用户和组信息?

[root@ ~]# cat /etc/group | grep mysql
[root@ ~]# cat /etc/passwd | grep mysql

创建mysql用户组

[root@localhost mysql-5.7.28]# groupadd mysql

创建一个用户名为mysql-3306的用户并加入mysql用户组

[root@localhost mysql-5.7.28]# useradd -g mysql mysql-3306
[root@localhost mysql-5.7.28]# passwd mysql-3306

制定password 为 yjw@2018 (密码不可太简单,会校验不过的哦)

[root@~]# passwd mysql
Changing password for user mysql.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.

解压tat包 我的路径 /usr/local/mysql/

[root@localhost mysql]# tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
[root@localhost mysql]# mv mysql-5.7.28-linux-glibc2.12-x86_64 mysql-3306

更改所属的组和用户

[root@localhost mysql]# chown -R mysql-3306 mysql-3306/
[root@localhost mysql]# chgrp -R mysql mysql-3306/
[root@localhost mysql]# cd mysql-3306/
[root@localhost mysql]# mkdir data

在/etc文件编辑my.cnf文件


[mysql]

# 设置mysql客户端默认字符集

default-character-set=utf8 

[mysqld]

skip-name-resolve

#设置3306端口

port =3306

# 设置mysql的安装目录

basedir=/usr/local/mysql/mysql

# 设置mysql数据库的数据的存放目录

datadir=/usr/local/mysql/mysql/data

# 允许最大连接数

max_connections=200

# 服务端使用的字符集默认为8比特编码的latin1字符集

character-set-server=utf8

# 创建新表时将使用的默认存储引擎

# default-storage-engine=INNODB 

lower_case_table_names=1

max_allowed_packet=16M

在/user/local/mysql/mysql/support-files文件编辑mysql.server文件

  basedir=/usr/local/mysql/mysql
  bindir=/usr/local/mysql/mysql/bin
  if test -z "$datadir"
  then
    datadir=/usr/local/mysql/mysql/data
  fi
  sbindir=/usr/local/mysql/mysql/bin
  libexecdir=/usr/local/mysql/mysql/bin

初始化数据库 (数据库目录不要用特殊字符,最好常规名称,避免不必要的麻烦)

以下已经弃用,仅做记录;
[root@localhost mysql-3306]# bin/mysql_install_db --user=mysqltest --basedir=/user/local/mysql/mysql/ --datadir=/user/local/mysql/mysql/data/
2019-11-21 12:28:51 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2019-11-21 12:28:51 [ERROR] Can’t locate the language directory.

网上查询显示新版本数据库以上方法已经弃用,可用一下方法,亲测可用;
[root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql/ --datadir=/usr/local/mysql/mysql/data/
2019-11-22T10:20:11.275791Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-11-22T10:20:11.742089Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-11-22T10:20:11.804639Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-11-22T10:20:11.864495Z 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: aac1a7b6-0d11-11ea-a376-000c29210e9a.
2019-11-22T10:20:11.865862Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2019-11-22T10:20:13.410072Z 0 [Warning] CA certificate ca.pem is self signed.
2019-11-22T10:20:13.696971Z 1 [Note] A temporary password is generated for root@localhost: XVaf93Xk%)GF

默认密码:(XVaf93Xk%)GF)

#设置开机启动

[root@localhost mysql]#  chkconfig --level 35 mysqld on
[root@localhost mysql]#  chkconfig --list mysqld

[root@localhost mysql]#  chmod +x /etc/rc.d/init.d/mysqld
[root@localhost mysql]#  chkconfig --add mysqld
[root@localhost mysql]#  chkconfig --list mysqld
[root@localhost mysql]#  service mysqld status
SUCCESS! MySQL running (7099)

etc/profile/
linux系统中给mysql配置环境变量

export PATH=$PATH:/usr/local/mysql/mysql/bin   设置环境变量后,mysql可以再任意目录登录
[root@localhost mysql]# source /etc/profile

初始化MySQL密码

mysqladmin -uroot -p'XVaf93Xk%)GF' password

[root@localhost mysql]# bin/mysqladmin -uroot -p'XVaf93Xk%)GF' password
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
New password: 
Confirm new password: 
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

查看端口: netstat -tunlp

查看服务状态:

[root@localhost mysql]# service mysql status
 SUCCESS! MySQL running (7099)

遇到的问题 -------------------------------------------------------------------------


my.cnf文件  文件的 default-storage-engine=INNODB 是会报如下错误:

[root@localhost mysql-3306]# bin/mysqld --initialize --user=mysql-3306 --basedir=/usr/local/mysql-5.7.28/mysql-3306/ --datadir=/usr/local/mysql-5.7.28/mysql-3306/data/
2019-11-21T08:40:50.652204Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-11-21T08:40:50.967610Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-11-21T08:40:51.013205Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-11-21T08:40:51.068645Z 0 [ERROR] Unknown/unsupported storage engine: INNODB
2019-11-21T08:40:51.068674Z 0 [ERROR] Aborting

[root@localhost mysql-3306]# /etc/init.d/mysqld restart
 ERROR! MySQL server PID file could not be found!
Starting MySQL.Logging to '/usr/local/mysql-5.7.28/mysql-3306/data/localhost.localdomain.err'.
 ERROR! The server quit without updating PID file (/usr/local/mysql-5.7.28/mysql-3306/data/localhost.localdomain.pid).
[root@localhost mysql-3306]# bin/mysql -uroot -p
Enter password: 
mysql: Character set 'utf8' is not a compiled character set and is not specified in the '/usr/local/mysql/share/charsets/Index.xml' file
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

mysql提示Character set ‘utf-8’ is not a compiled character set and is not specified:

[root@localhost mysql]# vim /etc/profile
[root@localhost mysql]# source /etc/profile
[root@localhost mysql]# mysql -v
mysql: Character set 'utf8' is not a compiled character set and is not specified in the '/usr/local/mysql/share/charsets/Index.xml' file
mysql: Character set 'utf8' is not a compiled character set and is not specified in the '/usr/local/mysql/share/charsets/Index.xml' file
ERROR 2019 (HY000): Can't initialize character set utf8 (path: /usr/local/mysql/share/charsets/)
[root@localhost mysql]# mysq
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章