设为首页 收藏本站
查看: 990|回复: 0

[经验分享] Linux centos安装mysql(解压手动安装)

[复制链接]

尚未签到

发表于 2018-9-29 09:34:50 | 显示全部楼层 |阅读模式
  系统版本:
  [root@localhost ~]# uname -r
  2.6.32-358.el6.i686
  [root@localhost ~]# cat /etc/issue

  CentOS>  Kernel \r on an \m
  下载linux generic 32bit的mysql包(http://dev.mysql.com/downloads/mysql/ )。
  步骤开始:
  1,直接wget下载,或者下载后上传到服务器端。
  2,解压。
  3,将解压生成的mysql目录复制到/usr/local/mysql,并在其下新建data目录。
  4,新建用户mysql和用户组mysql,并将mysql目录进行权限修改。
  [root@localhost local]# pwd
  /usr/local
  [root@localhost local]# chown -R mysql:mysql mysql/
  [root@localhost mysql]# ll
  total 56
  drwxr-xr-x.  2 mysql mysql  4096 Jun 26 01:42 bin
  -rw-r--r--.  1 mysql mysql 17987 Jun 26 01:42 COPYING
  drwxr-xr-x.  5 mysql mysql  4096 Jun 26 04:40 data
  drwxr-xr-x.  2 mysql mysql  4096 Jun 26 01:42 docs
  drwxr-xr-x.  3 mysql mysql  4096 Jun 26 01:42 include
  drwxr-xr-x.  5 mysql mysql  4096 Jun 26 01:43 lib
  drwxr-xr-x.  4 mysql mysql  4096 Jun 26 01:42 man
  -rw-r--r--.  1 mysql mysql  2478 Jun 26 01:39 README
  drwxr-xr-x. 28 mysql mysql  4096 Jun 26 01:42 share
  drwxr-xr-x.  2 mysql mysql  4096 Jun 26 01:43 support-files
  [root@localhost mysql]#
  [root@localhost mysql]# pwd
  /usr/local/mysql
  5,初始化数据。
  [root@localhost mysql]# ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
  [root@localhost mysql]#           //以上basedir   datadir目录是属于默认目录,若安装目录非
  //默认/usr/local/mysql,比如目录为/usr/local/mysql-5.7.13
  //则需要手动指定,并在目录下./support-files/mysql.server
  //文件中指定basedir和datadir的实际目录。
  //端口修改是在./support-files/my-default.cnf文件中。
  6,复制配制文件。
  [root@localhost mysql]# cp -a ./support-files/my-default.cnf /etc/my.cnf
  [root@localhost mysql]#
  7,将Mysql的服务脚本放到/etc/init.d/目录下。
  [root@localhost mysql]# cp -a ./support-files/mysql.server /etc/init.d/mysqld
  [root@localhost mysql]#
  8,启动服务。
  [root@localhost mysql]# service mysqld restart
  Shutting down MySQL.. SUCCESS!
  Starting MySQL.. SUCCESS!
  [root@localhost mysql]#
  9,查看初始密码,并登录mysql。
  [root@localhost mysql]# cat /root/.mysql_secret
  # Password set for user 'root@localhost' at 2016-06-26 02:48:47
  :jiDfmi%5kaK
  [root@localhost mysql]# ./bin/mysql -uroot -p
  Enter password: (此处输入上述密码)
  Welcome to the MySQL monitor.  Commands end with ; or \g.

  Your MySQL connection>  Server version: 5.7.13
  Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  Oracle is a registered trademark of Oracle Corporation and/or its
  affiliates. Other names may be trademarks of their respective
  owners.
  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  mysql>
  mysql> status    (下面会有报错,提示需要修改密码后再执行命令)

  ERROR 1820 (HY000): You must reset your password using>  mysql>
  10,修改mysql登录密码。
  [root@localhost mysql]# ./bin/mysqladmin -uroot -p password
  Enter password: (输入上述老密码)
  New password:
  Confirm new password:
  Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
  [root@localhost mysql]#
  11,使用新密码即可登录mysql。
  [root@localhost mysql]# ./bin/mysql -uroot -p
  Enter password: (新密码)
  Welcome to the MySQL monitor.  Commands end with ; or \g.

  Your MySQL connection>  Server version: 5.7.13 MySQL Community Server (GPL)
  Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  Oracle is a registered trademark of Oracle Corporation and/or its
  affiliates. Other names may be trademarks of their respective
  owners.
  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  mysql> select version();
  +-----------+
  | version() |
  +-----------+
  | 5.7.13    |
  +-----------+
  1 row in set (0.01 sec)
  mysql>
  12,至此mysql安装完成。
  报错解决:
  1,
  [root@localhost mysql-5.7.13]# ./bin/mysql_install_db --user=mysql
  2016-06-26 02:47:09 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
  2016-06-26 02:47:09 [ERROR]   The data directory needs to be specified.
  解决:需要新建data目录,指定安装目录(在非默认目录时需要指定,默认路径:/usr/local/mysql,同时需要指定./support-files/mysql.server中的basedir和datadir为相应路径)。
  [root@localhost mysql-5.7.13]# ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.7.13/ --datadir=/usr/local/mysql-5.7.13/data/
  2016-06-26 02:48:47 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
  2016-06-26 02:49:19 [WARNING] The bootstrap log isn't empty:
  2016-06-26 02:49:19 [WARNING] 2016-06-26T09:48:50.798592Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
  2016-06-26T09:48:50.898732Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
  2016-06-26T09:48:50.898778Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
  以上报错均因未在mysql.server中指定自定义的路径。
  2,启动mysql服务不成功。
  [root@localhost ~]# /etc/init.d/mysqld start
  /etc/init.d/mysqld: line 256: my_print_defaults: command not found
  Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
  解决:原来默认路径是/usr/local/mysql目录,这里存放目录是/usr/local/mysql-5.7.13。
  将mysql-5.7.13改为mysql再启动,发现如下错误:
  ERROR! MySQL server PID file could not be found!
  确认当前目录所有者为root,改为mysql:
  [root@localhost local]# chown -R mysql:mysql mysql/
  [root@localhost local]# /etc/init.d/mysqld restart
  ERROR! MySQL server PID file could not be found!
  Starting MySQL....... SUCCESS!
  3,登录不成功,是因为服务没启动。
  [root@localhost mysql-5.7.13]# cat /root/.mysql_secret
  # Password set for user 'root@localhost' at 2016-06-26 02:48:47
  :jiDfmi%5kaK
  [root@localhost mysql-5.7.13]# ./bin/mysql -uroot -p
  Enter password:
  ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
  解决:上面第2个问题解决后,此问题消失(需要将mysqld服务启动)。
  4,修改端口号后,启动服务报错:
  ERROR! MySQL server PID file could not be found!
  Starting MySQL.. ERROR! The server quit without updating PID file(/usr/local/mysql-5.7.13/data/CentOS.pid)
  解决:
  发现./data目录下果然没有CentOS.pid文件。
  查看./data/目录下的报错日志Centos.err。
  发现如下提示(主要查找 [ERROR]标识的,而[Warning]和[Note]可忽略 ):
  variable 'Port = 3308' 无法识别。
  在/etc/my.cnf中把Port改为port(大写P改为小写p),重新启动,正常。
  --文件默认是大写Port,但还是需要改为小写port。
  --另外说明查看错误信息/日志的重要性,很多问题可以自己发现解决。
  5,数据库无法登录问题:
  MYSQL提示:
  ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YSE)
  解决:
  [root@localhost mysql]# bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
  [root@localhost mysql]# bin/mysql -u mysql
DSC0000.jpg

  重置密码:
  mysql>update user set authentication_string=password('your_new_password') where user='root' ;
DSC0001.jpg

  *特别提醒注意的一点是,新版的mysql数据库下的user表中已经没有Password字段了,而是将加密后的用户密码存储于authentication_string字段。否则会提示:
  ERROR 1054 (42S22): Unknown column 'password' in 'field list'
  6, 提示如下信息:
  mysql> show databases;
  ERROR 1820 (HY000): You must reset your password using>
  解决:

  mysql>>  Query OK, 0 rows affected (0.46 sec)
  mysql> show databases;
  +--------------------+
  | Database           |
  +--------------------+
  | information_schema |
  | mysql              |
  | performance_schema |
  | sys                |
  +--------------------+
  4 rows in set (0.10 sec)
  mysql>
  参考:http://www.cnblogs.com/azhw/p/5143232.html


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-603594-1-1.html 上篇帖子: mysql 运维常用命令收录 下篇帖子: mysql——设置mysql大小写不敏感
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表