1、因为我的服务器的操作系统是centos7的,在MySQL官网下载的是
2、进入放压缩文件的目录下,解压文件
3、修改文件夹名
4、检查库文件是否有删除,若有便删除
5、检查mysql组和用户是否存在,如无创建
创建
[root@dbserver ~]#groupadd mysql
[root@dbserver ~]#useradd -r -g mysql mysql
//useradd -r参数表示mysql用户是系统用户,不可用于登录系统
6、在mysql下添加data目录
7、更改mysql目录下所有的目录及文件夹所属组合用户
8、安装和初始化数据库
报错 报错[ERROR] Can’t find error-message file
解决方法
[root@dbserver bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US2017-08-31T09:00:54.941514Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2017-08-31T09:00:56.364312Z 0 [Warning] InnoDB: New log files created, LSN=45790
9、
配置my.cnf
接下来进入/usr/local/mysql/support-files/目录下
查看是否存在my-default.cnf文件,如果存在直接copy到/etc/my.cnf文件中
[root@dbserver mysql]# cp -a ./support-files/my-default.cnf /etc/my.cnf
10、启动服务
11、
将mysqld服务加入开机自启动项。 将{mysql}/ support-files/mysql.server 拷贝为/etc/init.d/mysql并设置运行权限,这样就可以使用service mysql命令启动/停止服务, 否则就只能使用{mysql}/bin/mysqld_safe &命令来启动服务 还需要把mysql.server中basedir的相关路径,改为自定义的路径,默认路径是/usr/local/mysql
[root@iZ2ze6adlpez0hj58u529qZ bin]# cd /usr/local/mysql/support-files [root@iZ2ze6adlpez0hj58u529qZ support-files]# cp mysql.server /etc/init.d/mysql cp: overwrite ‘/etc/init.d/mysql’? [root@iZ2ze6adlpez0hj58u529qZ support-files]# chmod +x /etc/init.d/mysql
将mysql注册为开机启动 [root@iZ2ze6adlpez0hj58u529qZ support-files]# chkconfig --add mysql
查看是否成功 [root@iZ2ze6adlpez0hj58u529qZ support-files]# chkconfig --list mysql Note: This output shows SysV services only and does not include native systemd services. SysV configuration data might be overridden by native systemd configuration.
12、启动服务
13、登录mysql
在tmp/目录下寻找mysql.sock
如果不存在建立软连接
重启,如果还不行,修改my.cnf文件
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
[mysql]
default-character-set=utf8
[mysqld]
#skip-grant-tables
datadir=/var/lib/mysql
#datadir=/usr/local/mysql/data/
socket=/var/lib/mysql/mysql.sock
#socket=/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
socket=/var/lib/mysql/mysql.sock
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
#[mysql]
#basedir=/usr/local/mysql/
#datadir=/usr/local/mysql/data/
然后重新启动
密码错误,修改my.cnf文件在
[mysqld]中任意行添加
skip-grant-tables 作用避过mysql密码校验
14、重置密码
将password改为authentication_string
15、设置远程登录
密码设置太过简单
重设密码我的是大写字母+特殊符号+数字
转载:https://blog.csdn.net/zhou920786312/article/details/77750604