1:下载
[root@localhost soft]# wget https:
2:解压文件
[root@dbserver /]
3修改文件
[root@dbserver local]
4:检查库文件是否有删除,若有便删除(linux系统自带的)
[root@dbserver mysql]
删除
[root@dbserver mysql]
5:检查mysql组和用户是否存在,如无创建
[root@dbserver ~]
[root@dbserver ~]
创建
[root@dbserver ~]
[root@dbserver ~]
//useradd -r参数表示mysql用户是系统用户,不可用于登录系统
6:在mysql下添加data目录
[root@dbserver mysql]
7:更改mysql目录下所有的目录及文件夹所属组合用户
[root@dbserver mysql]
[root@dbserver local]
[root@dbserver local]
[root@dbserver local]
[root@dbserver mysql]
total 40
drwxr-xr-x. 2 mysql mysql 4096 Aug 31 16:45 bin
-rw-r--r--. 1 mysql mysql 17987 Jun 22 22:13 COPYING
drwxr-xr-x. 2 mysql mysql 6 Aug 31 16:48 data
drwxr-xr-x. 2 mysql mysql 52 Aug 31 16:45 docs
drwxr-xr-x. 3 mysql mysql 4096 Aug 31 16:44 include
drwxr-xr-x. 5 mysql mysql 4096 Aug 31 16:45 lib
drwxr-xr-x. 4 mysql mysql 28 Aug 31 16:45 man
-rw-r--r--. 1 mysql mysql 2478 Jun 22 22:13 README
drwxr-xr-x. 28 mysql mysql 4096 Aug 31 16:45 share
drwxr-xr-x. 2 mysql mysql 86 Aug 31 16:45 support-files
8:安装和初始化数据库
安装
./mysqld
2017-08-31T08:50:23.910440Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use
2017-08-31T08:50:23.910635Z 0 [ERROR] Can't find error-message file '/usr/local/mysql/
figuration directive.2017-08-31T08:50:24.709286Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-08-31T08:50:24.767540Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-08-31T08:50:24.892629Z 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: 6e083b8f-8e29-11e7-88b1-
005056b427be.2017-08-31T08:50:24.895674Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-08-31T08:50:24.896645Z 1 [Note] A temporary password is generated for root@localhost: gFamcspKm2+u
报错[ERROR] Can’t find error-message file ‘/usr/local/mysql/–datadir=/usr/local/mysql/data/share/errmsg.sys’. Check error-message file location and ‘lc-messages-dir’ con
解决
[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_US
2017-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
2017-08-31T09:00:56.602211Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-08-31T09:00:56.668145Z 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: e69986d2-8e2a-11e7-a335-
005056b427be.2017-08-31T09:00:56.671464Z 0 [Warning] Gtid table is not ready to be used. Table
2017-08-31T09:00:56.672453Z 1 [Note] A temporary password is generated for root@localhost: qfuqvCsHb2!.
9配置my.cnf
接下来进入/usr/local/mysql/support-files/目录下
查看是否存在my-default.cnf文件,如果存在直接copy到/etc/my.cnf文件中
[root@dbserver mysql]
如果不存在my-default.cnf文件,则在/etc/目录下创建my.cnf,并写入以下内容
#[mysql]
#basedir=/usr/local/mysql/
#datadir=/usr/local/mysql/data/
10启动服务
[root@dbserver mysql]
[root@dbserver bin]
[2] 10436
[root@dbserver bin]
2017-08-31T09:52:15.806633Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2017-08-31T09:52:16.292949Z mysqld_safe mysqld from pid file /var/run/mysql/mysql.pid ended
11将mysqld服务加入开机自启动项。
将{mysql}/ support-files/mysql.server 拷贝为/etc/init.d/mysql并设置运行权限,这样就可以使用service mysql命令启动/停止服务,
否则就只能使用{mysql}/bin/mysqld_safe &命令来启动服务
还需要把mysql.server中basedir的相关路径,改为自定义的路径,默认路径是/usr/local/mysql
[root@dbserver support-files]
[root@dbserver support-files]
[root@dbserver support-files]
[root@dbserver support-files]
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]'.
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
12启动服务
[root@dbserver bin]
Starting MySQL.Logging to '/var/log/mysql/mysql.log'.
ERROR! The server quit without updating PID file (/var/lib/mysql/dbserver.pid).
解决
[root@dbserver mysql]
rm: remove regular file '/etc/my.cnf'? y
[root@dbserver mysql]
Starting MySQL.Logging to '/usr/local/mysql/data/dbserver.err'.
SUCCESS!
[root@dbserver mysql]
Starting MySQL SUCCESS!
13登录mysql
[root@dbserver bin]
密码是第八步产生的密码
14设置密码
mysql> set password=password("root")
Query OK, 0 rows affected, 1 warning (0.00 sec)
注意不要使用单引号,为什么?你自己试试就知道了
15设置远程登录权限
mysql> grant all privileges on *.* to'root' @'%' identified by 'root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.06 sec)
mysql> quit
Bye
一般这个错误是由密码错误引起,解决的办法自然就是重置密码。
假设我们使用的是root账户。
1.重置密码的第一步就是跳过MySQL的密码认证过程,方法如下:
#vim /etc/my.cnf(注:windows下修改的是my.ini)
在文档内搜索mysqld定位到[mysqld]文本段:
/mysqld(在vim编辑状态下直接输入该命令可搜索文本内容)
在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程,如下图所示:
![](https://i-blog.csdnimg.cn/blog_migrate/5a79dbc32f3f8a59b1bc66375fddedb5.png)
保存文档并退出:
#:wq
2.接下来我们需要重启MySQL:
/etc/init.d/mysql restart(有些用户可能需要使用/etc/init.d/mysqld restart)
![](https://i-blog.csdnimg.cn/blog_migrate/acc7e89dcd5f5f161f13a67598aec40f.png)
3.重启之后输入#mysql即可进入mysql。
![](https://i-blog.csdnimg.cn/blog_migrate/192cb873183fad5b086e725dad1a9eb7.png)
4.接下来就是用sql来修改root的密码
mysql> use mysql;
mysql> update user set password=password("你的新密码") where user="root";
mysql> flush privileges;
mysql> quit
/
新安装的MySQL5.7,登录时提示密码错误,安装的时候并没有更改密码,后来通过免密码登录的方式更改密码,输入update mysql.user set password=password('root') where user='root'时提示ERROR 1054 (42S22): Unknown column 'password' in 'field list',原来是mysql数据库下已经没有password这个字段了,password字段改成了
authentication_string
所以更改语句替换为update mysql.user set authentication_string=password('root') where user='root' ;即可
到这里root账户就已经重置成新的密码了。
5.编辑my.cnf,去掉刚才添加的内容,然后重启MySQL。大功告成!
![](https://i-blog.csdnimg.cn/blog_migrate/936ecf0c925a01f74fa9885c22077696.png)