在安装过程中所遇到的问题有:
1、my-default.cnf文件找不到
2、mysql启动报错
3、MysqL临时密码无法登录
安装环境centos 6.0
下载数据库:
[root@CLanguage src]# pwd
/usr/local/src #下载文件存放路径(个人原因,可随意。)
[root@CLanguage src]#
wget https://cdn.MysqL.com//Downloads/MysqL-5.7/MysqL-5.7.21-linux-glibc2.12-x86_64.tar.gz
[root@CLanguage src]# tar -zxvf MysqL-5.7.21-linux-glibc2.12-x86_64.tar.gz #解压
[root@CLanguage src]# mv MysqL-5.7.21-linux-glibc2.12-x86_64 MysqL
#更改文件名
卸载旧版本:
[root@CLanguage src]# rpm -qa |grep MysqL
MysqL-5.1.47-4.el6.x86_64
MysqL-libs-5.1.47-4.el6.x86_64
MysqL-devel-5.1.47-4.el6.x86_64
[root@CLanguage src]# rpm -e --nodeps MysqL-5.1.47-4.el6.x86_64
[root@CLanguage src]# rpm -e --nodeps MysqL-libs-5.1.47-4.el6.x86_64
[root@CLanguage src]# rpm -e --nodeps MysqL-devel-5.1.47-4.el6.x86_64
[root@CLanguage src]# rpm -qa |grep MysqL
[root@CLanguage src]#
创建数据库目录以及用户和组:
[root@CLanguage src]#mkdir /data
[root@CLanguage src]#mkdir /data/MysqLdata #数据存放目录
[root@CLanguage src]#groupadd MysqL #创建MysqL组
[root@CLanguage src]#useradd -r -s /sbin/nologin -g MysqL MysqL -d /usr/local/src/MysqL #添加MysqL用户使其shell模式为nologin(禁止登录),
[root@CLanguage MysqL]# chown -R MysqL .
[root@CLanguage MysqL]# chgrp -R MysqL .
[root@CLanguage MysqL]#chown -R MysqL /data/MysqLdata
安装前先安装numactl组件,或者会报错:bin/MysqLd: error while loading shared libraries: libnuma.so.1
[root@CLanguage MysqL]# yum -y install numactl
(可以使用本地CD yum源进行安装,前提是搭建好后。)
配置参数:
[root@CLanguage src]# cd MysqL
[root@CLanguage MysqL]# bin/MysqLd --initialize --user=MysqL --basedir=/usr/local/src/MysqL --datadir=/data/MysqLdata/ #配置参数
2018-01-31T08:41:32.144065Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-01-31T08:41:34.501273Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-01-31T08:41:34.943351Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-01-31T08:41:35.016168Z 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: 8b673fc1-0662-11e8-a70a-000c298536ba.
2018-01-31T08:41:35.021358Z 0 [Warning] Gtid table is not ready to be used. Table 'MysqL.gtid_executed' cannot be opened.
2018-01-31T08:41:35.025019Z 1 [Note] A temporary password is generated for root@localhost: dhaMrqAVZ5-C {最后的root@localhost:后面为临时密码}
--basedir=/usr/local/src/MysqL #MysqL文件所在目录
--datadir=/data/MysqLdata/ #数据库存放目录
[root@CLanguage MysqL]# bin/MysqL_ssl_rsa_setup --datadir=/data/MysqLdata/
#配置参数
修改系统配置文件:
在support-files目录未发现my-default.cnf文件,所以只能手动创建了。
[root@CLanguage support-files]# vim /etc/my.cnf (创建my.cnf,将以下代码复制进去,记得下面几个目录需要自己手动修改为自己定义的目录)
[client]
port = 3306
socket = /tmp/MysqL.sock
[MysqLd]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/src/MysqL #文件存放目录
datadir=/data/MysqLdata/ #数据库存放目录
socket=/tmp/MysqL.sock #以上面socket值要一致
log-error=/var/log/MysqLd.log
pid-file=/var/run/MysqLd/MysqLd.pid
lower_case_table_names = 1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_connections=5000
default-time_zone = '+8:00'
(这里参数不全,可以去其他地方拷贝一个my.cnf文件)
或者拷贝以下内容:
[MysqLd]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES # 一般配置选项
basedir = /usr/local/src/MysqL #需修改
datadir = /data/MysqLdata #需修改
port = 3306
socket = /var/run/MysqLd/MysqLd.sock
character-set-server=utf8
back_log = 300
max_connections = 3000
max_connect_errors = 50
table_open_cache = 4096
max_allowed_packet = 32M
#binlog_cache_size = 4M
max_heap_table_size = 128M
read_rnd_buffer_size = 16M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 16
query_cache_size = 128M
query_cache_limit = 4M
ft_min_word_len = 8
thread_stack = 512K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 128M
#log-bin=MysqL-bin
long_query_time = 6
server_id=1
innodb_buffer_pool_size = 1G
innodb_thread_concurrency = 16
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = on
[MysqLdump]
quick
max_allowed_packet = 32M
[MysqL]
no-auto-rehash
default-character-set=utf8
safe-updates
[myisamchk]
key_buffer = 16M
sort_buffer_size = 16M
read_buffer = 8M
write_buffer = 8M
[MysqLhotcopy]
interactive-timeout
[MysqLd_safe]
open-files-limit = 8192
[root@CLanguage support-files]# cp MysqL.server /etc/init.d/MysqLd
[root@CLanguage support-files]# vim /etc/init.d/MysqLd
修改/etc/init.d/MysqLd在basedir和datadir后填入文件存放路径和数据存放路径
启动MysqL:
[root@CLanguage MysqL]# bin/MysqLd_safe --user=MysqL & #检测
[root@CLanguage run]# /etc/init.d/MysqL start (这里会报错,因为找不到MysqLd文件夹,所以要创建并赋予权限。)
[root@CLanguage MysqL]# cd /var/run/
[root@CLanguage run]# mkdir MysqLd
[root@CLanguage run]# chown -R MysqL MysqLd
[root@CLanguage run]# chgrp -R MysqL MysqLd
[root@CLanguage run]# /etc/init.d/MysqLd start
Starting MysqL... [ OK ]
登录MysqL已经修改密码:
如果使用bin/MysqL -uroot -p无法登录时,可以使用以下办法进行密码重设:
修改/etc/my.cnf文件
在[MysqLd]下面添加“skip-grant-tables”
(skip-grant-tables命令为跳过验证,直接登录。个人认为好比linux的单用户模式,来进行MysqL的密码修改。)
重启MysqL
在命令行中输入bin/MysqL进行登录(直接输入MySQL命令可能提示找不到命令。因为path路径未设定,后面添加path路径说明。)
MysqL> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| MysqL |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
MysqL> USE MysqL; #选择数据库
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MysqL> update user set authentication_string=password('123abc') where user='root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 1
MysqL> flush privileges; #刷新权限
Query OK, 0 rows affected (0.00 sec)
MysqL> quit;
Bye
重新登录MysqL
[root@CLanguage run]#MysqL -uroot -p123abc
修改完成后,注销my.cnf中的“skip-grant-tables”
修改环境变量:
将MysqL的bin路径添加到/etc/profile
[root@CLanguage MysqL]# vim /etc/profile
添加:
export PATH=/usr/local/src/MysqL/bin:$PATH
[root@CLanguage MysqL]# source /etc/profile
配置MysqL自动启动
[root@CLanguage MysqL]#chmod 755 /etc/init.d/MysqLd
[root@CLanguage MysqL]#chkconfig --add MysqLd
[root@CLanguage MysqL]#chkconfig --level 345 MysqLd on
在使用过程中,发现重启电脑,MysqL无法启动。报PID文件找不到,存放PID文件的路径为:/var/run/MysqLd下面,每次重启完在/var/run/目录中都找不到MysqLd文件夹,都需要重新创建一次MysqLd文件夹和修改文件夹的所属用户和组,才能正常使用。
解决方法
因为之所以/var/run/MysqLd 目录每次重启后都需要手动去创建,是因为/var/run/目录下建立文件夹是在内存中,故每次重启后内存被清空导致/var/run/MysqLd 也被清除,从而导致无法启动MysqL。
创建一个MysqLd.pid文件存放目录,重新修改文件夹所属用户和组。修改my.cnf文件,找到pid-file=/var/run/MysqLd/MysqLd.pid将MysqLd.pid存放路径修改到其他存放位置。具体操作如下:
重新启动MysqL正常运行。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。