1、下载安装包

http://dev.mysql.com/downloads/mysql/#downloads

linux下安装mysql 5.7数据库

下载: 搜狐的镜像站还是比较快的: http://mirrors.sohu.com/

2.检查库文件是否存在,如有删除。
[[email protected] Desktop]$ rpm -qa | grep mysql
mysql-libs-5.1.52-1.el6_0.1.x86_64
[[email protected] ~]# rpm -e mysql-libs-5.1.52.x86_64 --nodeps

3.检查mysql组和用户是否存在,如无创建。
[[email protected] ~]# cat /etc/group | grep mysql
mysql:x:490:
[[email protected] ~]# cat /etc/passwd | grep mysql
mysql:x:496:490::/home/mysql:/bin/bash
以上为默认存在的情况,如无,执行添加命令:
[[email protected] ~]#groupadd mysql
[[email protected] ~]#useradd -r -g mysql mysql
//useradd -r参数表示mysql用户是系统用户,不可用于登录系统。

4.解压TAR包,更改所属的组和用户
[[email protected] ~]# cd /tmp/
[[email protected] local]# tar xvfz mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
[[email protected] local]# mv mysql-5.7.12-linux-glibc2.5-x86_64 mysql
[[email protected] tmp]# cd /usr/local/mysql/
[[email protected] mysql]# ls -l
总用量 52
drwxr-xr-x.  2 root root  4096 6月  12 00:51 bin
-rw-r--r--.  1 root root 17987 6月  12 00:51 COPYING
drwxr-xr-x.  2 root root  4096 6月  12 00:51 docs
drwxr-xr-x.  3 root root  4096 6月  12 00:51 include
drwxr-xr-x.  5 root root  4096 6月  12 00:51 lib
drwxr-xr-x.  4 root root  4096 6月  12 00:51 man
-rw-r--r--.  1 root root  2478 6月  12 00:51 README
drwxr-xr-x. 28 root root  4096 6月  12 00:51 share
drwxr-xr-x.  2 root root  4096 6月  12 00:51 support-files
[[email protected] local]# chown -R mysql mysql/
[[email protected] local]# chgrp -R mysql mysql/
[[email protected] local]# cd mysql/


5.安装和初始化数据库
[[email protected] mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/
2016-06-01 15:23:25 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-06-01 15:23:30 [WARNING] The bootstrap log isn't empty:
2016-06-01 15:23:30 [WARNING] 2016-06-01T22:23:25.491840Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2016-06-01T22:23:25.492256Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2016-06-01T22:23:25.492260Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)


[[email protected] mysql]# cp -a ./support-files/my-default.cnf /etc/my.cnf
[[email protected] mysql]# cp -a ./support-files/mysql.server  /etc/init.d/mysqld

[[email protected] mysql]# cd bin/
[[email protected] bin]# ./mysqld_safe --user=mysql &
[1] 2932
[[email protected] bin]# 2016-06-01T22:27:09.708557Z mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
2016-06-01T22:27:09.854913Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

[[email protected] bin]# /etc/init.d/mysqld restart
Shutting down MySQL..2016-06-01T22:27:50.498694Z mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended
 SUCCESS! 
Starting MySQL. SUCCESS! 
[1]+  Done                    ./mysqld_safe --user=mysql
[[email protected] bin]# 
//设置开机启动
[[email protected] bin]# chkconfig --level 35 mysqld on
[[email protected] bin]#
-----------------------------------------------------------------------------------

如果启动报错,建议重新初始化。

MySQL server PID file could not be found! 

---------------------------------------------------------------------

6.初始化密码
mysql5.7会生成一个初始化密码,而在之前的版本首次登陆不需要登录。
[[email protected] bin]# cat /root/.mysql_secret 
# Password set for user '[email protected]' at 2016-06-01 15:23:25 
,xxxxxR5H9
[[email protected] bin]# ./mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.12

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> SET PASSWORD = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

7.添加远程访问权限

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 host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0


mysql> select host, user from user;
+-----------+-----------+
| host      | user      |
+-----------+-----------+
| %         | root      |
| localhost | mysql.sys |
+-----------+-----------+
重启生效

/etc/init.d/mysqld restart

【完】

mysql: error while loading shared libraries: libmysqlclient.so.16

遇到这个报错,直接安装

yum install mysql-devel mysql-libs



相关文章:

  • 2021-12-04
  • 2021-12-16
  • 2021-04-25
  • 2022-01-12
猜你喜欢
  • 2022-02-06
  • 2022-02-26
  • 2021-10-21
  • 2021-04-12
  • 2021-09-04
  • 2022-02-06
  • 2022-02-06
相关资源
相似解决方案