Mysql一个熟悉的概念,一个全新的知识领域。开始我全方位数据库学习之旅。
一切,从安装开始,自己动手每一步。
Linux在安装的过程中,可以勾选Mysql的安装,但是安装的版本是Mysql-5.1.73,版本非常低。必须重新安装,当前最新版本是5.7。但是卸载再安装,明显比空白Linux安装麻烦一点。
下面开始卸载/安装过程。
1. Mysql下载地址
1
<code>https://dev.mysql.com/downloads/file/?id=469494</code>
2. 确认OS版本
2
3
<code># more /etc/issue</code>
<code>CentOS release 6.7 (Final)</code>
<code>Kernel \r </code><code>on</code> <code>an \m</code>
4
5
6
<code># lsb_release -a</code>
<code>LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch</code>
<code>Distributor ID: CentOS</code>
<code>Description: CentOS release 6.7 (Final)</code>
<code>Release: 6.7</code>
<code>Codename: Final</code>
3. 根据OS版本,找到需要下载的Mysql版本,右键“将链接另存为”,即可获得下载地址
<a href="https://s2.51cto.com/wyfs02/M02/9B/CB/wKiom1lnJfny6OMnAAFkFpwtApI810.png-wh_500x0-wm_3-wmp_4-s_2046162689.png" target="_blank"></a>
4. 到Linux下,通过wget下载
<code>wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.18-1.el6.x86_64.rpm</code>
下面三个rpm包存在依赖关系,也需要下载
<code># wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-common-5.7.18-1.el6.x86_64.rpm</code>
<code># wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-client-5.7.18-1.el6.x86_64.rpm</code>
<code># wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-libs-5.7.18-1.el6.x86_64.rpm</code>
5. 检查查询发现,已经安装Mysql-5.1.73,版本非常低。必须重新安装,当前最新版本是5.7
<code># rpm -qa | grep mysql</code>
<code>mysql-server-5.1.73-5.el6_6.x86_64</code>
<code>mysql-libs-5.1.73-5.el6_6.x86_64</code>
<code>mysql-5.1.73-5.el6_6.x86_64</code>
<code>mysql-connector-odbc-5.1.5r1144-7.el6.x86_64</code>
6. 准备安装,安装前,就怀疑,会不会覆盖?会不会冲突?安装一下试试,就知道了。
同时安装4个rpm包
<code># rpm -ivh mysql-community-server-5.7.18-1.el6.x86_64.rpm mysql-community-client-5.7.18-1.el6.x86_64.rpm mysql-community-common-5.7.18-1.el6.x86_64.rpm mysql-community-libs-5.7.18-1.el6.x86_64.rpm</code>
7. 果然冲突了
7
8
<code>warning: mysql-community-server-5.7.18-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, </code><code>key</code> <code>ID 5072e1f5: NOKEY</code>
<code>Preparing... ########################################### [100%]</code>
<code>file /usr/share/mysql/czech/errmsg.sys </code><code>from</code> <code>install </code><code>of</code> <code>mysql-community-common-5.7.18-1.el6.x86_64 conflicts </code><code>with</code> <code>file </code><code>from</code> <code>package mysql-libs-5.1.73-5.el6_6.x86_64</code>
<code>file /usr/share/mysql/danish/errmsg.sys </code><code>from</code> <code>install </code><code>of</code> <code>mysql-community-common-5.7.18-1.el6.x86_64 conflicts </code><code>with</code> <code>file </code><code>from</code> <code>package mysql-libs-5.1.73-5.el6_6.x86_64</code>
<code>file /usr/share/mysql/dutch/errmsg.sys </code><code>from</code> <code>install </code><code>of</code> <code>mysql-community-common-5.7.18-1.el6.x86_64 conflicts </code><code>with</code> <code>file </code><code>from</code> <code>package mysql-libs-5.1.73-5.el6_6.x86_64</code>
<code>file /usr/share/mysql/english/errmsg.sys </code><code>from</code> <code>install </code><code>of</code> <code>mysql-community-common-5.7.18-1.el6.x86_64 conflicts </code><code>with</code> <code>file </code><code>from</code> <code>package mysql-libs-5.1.73-5.el6_6.x86_64</code>
<code>file /usr/share/mysql/estonian/errmsg.sys </code><code>from</code> <code>install </code><code>of</code> <code>mysql-community-common-5.7.18-1.el6.x86_64 conflicts </code><code>with</code> <code>file </code><code>from</code> <code>package mysql-libs-5.1.73-5.el6_6.x86_64</code>
<code>......</code>
8. 经过查询,也安装失败了,还是5.1.73版本
<code># rpm -qa|grep mysql</code>
9. 开始卸载原有的5.1.73的Mysql,几种卸载方式,首推YUM方式卸载
<code># yum remove mysql</code>
<code># rpm -e mysql // 普通删除模式 </code>
<code># rpm -e </code><code>--nodeps mysql // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除</code>
10 .还剩余下面两个包
11. 执行yum localinstall安装,发现需要卸载mysql-libs-5.1.73-5.el6_6.x86_64,通过yun卸载这个包后,可以安装了。
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<code># yum localinstall mysql-community-server-5.7.18-1.el6.x86_64.rpm mysql-community-client-5.7.18-1.el6.x86_64.rpm mysql-community-common-5.7.18-1.el6.x86_64.rpm mysql-community-libs-5.7.18-</code>
<code>1.el6.x86_64.rpm</code>
<code>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</code>
<code>Loaded plugins: fastestmirror, refresh-packagekit, security</code>
<code>Setting up </code><code>Local</code> <code>Package Process</code>
<code>Examining mysql-community-server-5.7.18-1.el6.x86_64.rpm: mysql-community-server-5.7.18-1.el6.x86_64</code>
<code>Marking mysql-community-server-5.7.18-1.el6.x86_64.rpm </code><code>to</code> <code>be installed</code>
<code>Loading mirror speeds </code><code>from</code> <code>cached hostfile</code>
<code>* base: mirrors.163.com</code>
<code>* extras: mirrors.cn99.com</code>
<code>* updates: mirrors.163.com</code>
<code>Examining mysql-community-client-5.7.18-1.el6.x86_64.rpm: mysql-community-client-5.7.18-1.el6.x86_64</code>
<code>Marking mysql-community-client-5.7.18-1.el6.x86_64.rpm </code><code>to</code> <code>be installed</code>
<code>Examining mysql-community-common-5.7.18-1.el6.x86_64.rpm: mysql-community-common-5.7.18-1.el6.x86_64</code>
<code>Marking mysql-community-common-5.7.18-1.el6.x86_64.rpm </code><code>to</code> <code>be installed</code>
<code>Examining mysql-community-libs-5.7.18-1.el6.x86_64.rpm: mysql-community-libs-5.7.18-1.el6.x86_64</code>
<code>Marking mysql-community-libs-5.7.18-1.el6.x86_64.rpm </code><code>to</code> <code>be installed</code>
<code>Resolving Dependencies</code>
<code>--> Running transaction check</code>
<code>---> Package mysql-community-client.x86_64 0:5.7.18-1.el6 will be installed</code>
<code>---> Package mysql-community-common.x86_64 0:5.7.18-1.el6 will be installed</code>
<code>---> Package mysql-community-libs.x86_64 0:5.7.18-1.el6 will be installed</code>
<code>---> Package mysql-community-server.x86_64 0:5.7.18-1.el6 will be installed</code>
<code>--> Finished Dependency Resolution</code>
<code>Dependencies Resolved</code>
<code>==================================================================================================================================</code>
<code>Package Arch Version Repository </code><code>Size</code>
<code>Installing:</code>
<code>mysql-community-client x86_64 5.7.18-1.el6 /mysql-community-client-5.7.18-1.el6.x86_64 100 M</code>
<code>mysql-community-common x86_64 5.7.18-1.el6 /mysql-community-common-5.7.18-1.el6.x86_64 2.5 M</code>
<code>mysql-community-libs x86_64 5.7.18-1.el6 /mysql-community-libs-5.7.18-1.el6.x86_64 8.9 M</code>
<code>mysql-community-server x86_64 5.7.18-1.el6 /mysql-community-server-5.7.18-1.el6.x86_64 769 M</code>
<code>Transaction</code> <code>Summary</code>
<code>Install 4 Package(s)</code>
<code>Total </code><code>size</code><code>: 880 M</code>
<code>Installed </code><code>size</code><code>: 880 M</code>
<code>Is</code> <code>this ok [y/N]: y</code>
<code>Downloading Packages:</code>
<code>Running rpm_check_debug</code>
<code>Running </code><code>Transaction</code> <code>Test</code>
<code>Transaction</code> <code>Test Succeeded</code>
<code>Running </code><code>Transaction</code>
<code>Installing : mysql-community-common-5.7.18-1.el6.x86_64 1/4</code>
<code>Installing : mysql-community-libs-5.7.18-1.el6.x86_64 2/4</code>
<code>Installing : mysql-community-client-5.7.18-1.el6.x86_64 3/4</code>
<code>Installing : mysql-community-server-5.7.18-1.el6.x86_64 4/4</code>
<code>Verifying : mysql-community-server-5.7.18-1.el6.x86_64 1/4</code>
<code>Verifying : mysql-community-libs-5.7.18-1.el6.x86_64 2/4</code>
<code>Verifying : mysql-community-common-5.7.18-1.el6.x86_64 3/4</code>
<code>Verifying : mysql-community-client-5.7.18-1.el6.x86_64 4/4</code>
<code>Installed:</code>
<code>mysql-community-client.x86_64 0:5.7.18-1.el6 mysql-community-common.x86_64 0:5.7.18-1.el6</code>
<code>mysql-community-libs.x86_64 0:5.7.18-1.el6 mysql-community-server.x86_64 0:5.7.18-1.el6</code>
<code>Complete!</code>
12. 最后检查,已经安装成功
<code>mysql-community-client-5.7.18-1.el6.x86_64</code>
<code>mysql-community-libs-5.7.18-1.el6.x86_64</code>
<code>mysql-community-common-5.7.18-1.el6.x86_64</code>
<code>mysql-community-server-5.7.18-1.el6.x86_64</code>
13. 安装完成,但是启动的时候遇到了问题:
<code># service mysqld restart</code>
<code>Stopping mysqld: [ OK ]</code>
<code>Initializing MySQL </code><code>database</code><code>: 2017-07-11T15:23:50.462866Z 0 [Warning] </code><code>TIMESTAMP</code> <code>with</code> <code>implicit </code><code>DEFAULT</code> <code>value </code><code>is</code> <code>deprecated. Please use </code><code>--explicit_defaults_for_timestamp server option (see documentation for more details).</code>
<code>2017-07-11T15:23:50.465315Z 0 [ERROR] </code><code>--initialize specified but the data directory has files in it. Aborting.</code>
<code>2017-07-11T15:23:50.465365Z 0 [ERROR] Aborting</code>
<code>[FAILED]</code>
14. 百度的解决方法(是由于之前老版本的数据库已经占用这个文件夹,需要清空,或者在/etc/my.cnf中重新指定--datadir)
保证 --datadir目录为空。 /usr/local/var/mysql 这个目录
15. 启动成功
<code># cd /var/lib/mysql</code>
<code># ls</code>
<code>auto.cnf ib_buffer_pool ibdata1 ib_logfile0 ib_logfile1</code>
<code># rm *</code>
<code>rm: remove regular file `auto.cnf</code><code>'? y</code>
<code>rm: remove regular file `ib_buffer_pool'</code><code>? y</code>
<code>rm: remove regular file `ibdata1</code><code>'? y</code>
<code>rm: remove regular file `ib_logfile0'</code><code>? y</code>
<code>rm: remove regular file `ib_logfile1'? y</code>
# service mysqld restart
<code>Initializing MySQL </code><code>database</code><code>: [ OK ]</code>
<code>Installing validate </code><code>password</code> <code>plugin: [ OK ]</code>
<code>Starting mysqld: [ OK ]</code>
# ps -ef|grep mysql
<code>root 4533 1 0 23:25 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe </code><code>--datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql</code>
<code>mysql 4727 4533 4 23:25 pts/0 00:00:00 /usr/sbin/mysqld </code><code>--basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock</code>
<code>root 4762 3752 0 23:25 pts/0 00:00:00 grep mysql</code>
16. 然而启动的过程中,又遇到一些问题,密码不知道了,重置密码
<code># mysql -u root</code>
<code>ERROR 1045 (28000): Access denied </code><code>for</code> <code>user</code> <code>'root'</code><code>@</code><code>'localhost'</code> <code>(using </code><code>password</code><code>: </code><code>NO</code><code>)</code>
<code>[root@test mysql]# mysql -u root -p</code>
<code>Enter </code><code>password</code><code>:</code>
<code>ERROR 1045 (28000): Access denied </code><code>for</code> <code>user</code> <code>'root'</code><code>@</code><code>'localhost'</code> <code>(using </code><code>password</code><code>: YES)</code>
编辑mysql配置文件/etc/my.cnf,在[mysqld]这个条目下加入 skip-grant-tables 保存退出后重启mysql
# vi /etc/my.cnf
<code>[root@test mysql]# service mysqld restart</code>
# mysql
<code>Welcome </code><code>to</code> <code>the MySQL monitor. Commands </code><code>end</code> <code>with</code> <code>; </code><code>or</code> <code>\g.</code>
<code>Your MySQL </code><code>connection</code> <code>id </code><code>is</code> <code>4</code>
<code>Server version: 5.7.18 MySQL Community Server (GPL)</code>
<code>Copyright (c) 2000, 2017, Oracle </code><code>and</code><code>/</code><code>or</code> <code>its affiliates. </code><code>All</code> <code>rights reserved.</code>
<code>Oracle </code><code>is</code> <code>a registered trademark </code><code>of</code> <code>Oracle Corporation </code><code>and</code><code>/</code><code>or</code> <code>its</code>
<code>affiliates. Other names may be trademarks </code><code>of</code> <code>their respective</code>
<code>owners.</code>
<code>Type </code><code>'help;'</code> <code>or</code> <code>'\h'</code> <code>for</code> <code>help. Type </code><code>'\c'</code> <code>to</code> <code>clear the </code><code>current</code> <code>input statement.</code>
<code>mysql> show databases;</code>
<code>+</code><code>--------------------+</code>
<code>| </code><code>Database</code> <code>|</code>
<code>| information_schema |</code>
<code>| mysql |</code>
<code>| performance_schema |</code>
<code>| sys |</code>
<code>4 </code><code>rows</code> <code>in</code> <code>set</code> <code>(0.00 sec)</code>
设置密码,然后删除/etc/my.cnf中的 skip-grant-tables
再次重启mysql
<code>mysql> use mysql;</code>
<code>Database</code> <code>changed</code>
--.给root用户设置新密码:
5.7版本之前:
<code>mysql> </code><code>update</code> <code>user</code> <code>set</code> <code>password</code><code>=</code><code>password</code><code>(</code><code>"新密码"</code><code>) </code><code>where</code> <code>user</code><code>=</code><code>"root"</code><code>;</code>
<code>Query OK, 1 </code><code>rows</code> <code>affected (0.01 sec)</code>
<code>Rows</code> <code>matched: 1 Changed: 1 Warnings: 0</code>
在5.7版本之后,mysql数据库下已经没有password这个字段了,password字段改成了authentication_string。
<code>update</code> <code>mysql.</code><code>user</code> <code>set</code> <code>authentication_string=</code><code>PASSWORD</code><code>(</code><code>'oracle'</code><code>) </code><code>where</code> <code>User</code><code>=</code><code>'root'</code><code>;</code>
<code>mysql> flush </code><code>privileges</code><code>;</code>
<code>Query OK, 0 </code><code>rows</code> <code>affected (0.00 sec)</code>
---退出mysql,重启然后重新登录
# mysql -uroot -poracle
<code>mysql: [Warning] Using a </code><code>password</code> <code>on</code> <code>the command line interface can be insecure.</code>
<code>Your MySQL </code><code>connection</code> <code>id </code><code>is</code> <code>5</code>
<code>Server version: 5.7.18</code>
<code>mysql></code>
<code></code>
本文转自 hsbxxl 51CTO博客,原文链接:http://blog.51cto.com/hsbxxl/1947164,如需转载请自行联系原作者