安装

  1. # 第一步 上传.tar.gz文件并解压
  2. # 第二步 创建mysql用户,并更改/usr/local/mysql目录的权限(用户和组)
  3. [root@Hive ~]# useradd -r -s /sbin/nologin mysql
  4. [root@Hive ~]# chown -R mysql.mysql /usr/local/mysql
  5. # 注意 如果有mariadb-libs则需要移除
  6. [root@Hive ~]# yum remove mariadb-libs
  7. # 第三步 初始化数据库
  8. # ---------------
  9. [root@Hive mysql]# ./scripts/mysql_install_db --user=mysql
  10. -bash: ./scripts/mysql_install_db: /usr/bin/perl: 坏的解释器: 没有那个文件或目录
  11. [root@Hive mysql]# yum -y install perl perl-devel
  12. # ---------------
  13. [root@Hive mysql]# ./scripts/mysql_install_db --user=mysql
  14. FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
  15. Data::Dumper
  16. [root@Hive mysql]# yum install -y perl-Data-Dumper
  17. # ---------------
  18. [root@Hive mysql]# ./scripts/mysql_install_db --user=mysql
  19. # 第四步 复制server脚本
  20. [root@Hive mysql]# cp support-files/mysql.server /etc/init.d/mysql
  21. # 第五步 启动MySQL
  22. [root@Hive mysql]# service mysql start
  23. # 第六步 设置密码并登录
  24. [root@Hive mysql]# bin/mysqladmin -u root password 'root'
  25. Warning: Using a password on the command line interface can be insecure.
  26. [root@Hive mysql]# bin/mysql -uroot -p
  27. Enter password:

配置

cp /usr/mysql/mysql/support-files/my-default.cnf /etc/my.cnf
vi /etc/my.cnf

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8 
[mysqld]
skip-name-resolve
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=/usr/mysql/mysql
# 设置mysql数据库的数据的存放目录
datadir=/usr/mysql/mysql/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_name=1
max_allowed_packet=16M

执行命令

[root@hive scripts]# ./mysql_install_db --user=root --basedir=/usr/mysql/mysql/ --datadir=/usr/mysql/mysql/data/

FATAL ERROR: please install the following Perl modules before executing ./mysql_install_db:
Data::Dumper

[root@hive scripts]# yum install autoconf

[root@hive scripts]# yum -y install perl perl-devel
[root@hive scripts]# yum install -y perl-Data-Dumper

[root@hive mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@hive mysql]# chkconfig --add mysqld
[root@hive mysql]# chkconfig --list mysqld

#注:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。 要列出 systemd 服务,请执行 'systemctl list-unit-files'。查看在具体 target 启用的服务请执行'systemctl list-dependencies [target]'。mysqld             0:关    1:关    2:开    3:开    4:开    5:开    6:关