Centos6.5安装mysql 5.7
Posted hoojjack
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos6.5安装mysql 5.7相关的知识,希望对你有一定的参考价值。
1、在官网下载安装包:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz
2、将安装包上传到centos上我安装的目录是在 /usr/local/
1 [[email protected] bin]# cd / 2 [[email protected] /]# cd usr 3 [[email protected] usr]# cd local/ 4 [[email protected] local]# ls 5 bin etc games include lib lib64 libexec sbin share src 6 [[email protected] local]# rz 7 8 [[email protected] local]# ls 9 bin etc games include lib lib64 libexec mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz sbin share src 10 [[email protected] local]# tar -xzvf mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz
3、将压缩包解压:tar -xzvf mysql-5.7.10...
10 [[email protected] local]# tar -xzvf mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz
4、重命名解压后的文件: mv mysql-5.7.10... mysql
1 [[email protected] local]# ls 2 bin games lib libexec mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz share 3 etc include lib64 mysql-5.7.10-linux-glibc2.5-x86_64 sbin src 4 [[email protected] local]# mv mysql-5.7.10-linux-glibc2.5-x86_64 mysql 5 [[email protected] local]# ls 6 bin etc games include lib lib64 libexec mysql mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz sbin share src
5、启动mysql的安装文件
1 [[email protected] mysql]# ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 2 2017-09-28 11:21:54 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize 3 2017-09-28 11:21:59 [WARNING] The bootstrap log isn‘t empty: 4 2017-09-28 11:21:59 [WARNING] 2017-09-28T03:21:55.455859Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
注意warning部分:mysql_install_db已经被取代了:
./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize
6、设置mysql的my.cnf配置 ( 将mysql下的文件复制一份到/etc/目录下 )
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
7、修改my.cnf里面的内容:
1 [mysqld] 2 basedir=/usr/local/mysql 3 datadir=/usr/local/mysql/data 4 port=3306 5 socket=/usr/local/mysql/mysqld.sock 6 7 [client] 8 default-character-set=utf8 9 socket=/usr/local/mysql/mysqld.sock 10 11 [mysql] 12 default-character-set=utf8 13 socket=/usr/local/mysql/mysqld.sock
一开始没有设置mysql的socket,而报
1 ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)
设置好socket 就解决了,其实创建软连接也是不错的选择:ln -s /usr/local/mysql/mysqld.sock /tmp/mysql.sock
8、启动mysql :
[[email protected] etc]# service mysqld restart
9、提示修改密码:
1 [[email protected] etc]# mysql 2 ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO) 3 [[email protected] etc]# mysql -uroot -p 4 Enter password:
10、查看mysql的默认密码:
1 [[email protected] ~]# cat /root/.mysql_secret 2 # Password set for user ‘[email protected]‘ at 2017-09-28 11:21:55 3 UQ?x&q+gu#o*
11、用默认密码登录后修改默认密码:
1 mysql> set password = password("root") 2 -> ; 3 Query OK, 0 rows affected, 1 warning (0.00 sec) 4 5 mysql> flush privileges; 6 Query OK, 0 rows affected (0.00 sec) 7 8 mysql> use mysql
然后就可以自己对数据库进行相应的操作了。
以上是关于Centos6.5安装mysql 5.7的主要内容,如果未能解决你的问题,请参考以下文章
Linux 使用rpm方式安装最新mysql(5.7)步骤以及常见问题解决
Linux(CentOS6.5)下编译安装MySQL Community Server 5.7.12
新手小白Linux(Centos6.5)部署java web项目(mysql5.7安装及相关操作)