linux下的mysql安装
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux下的mysql安装相关的知识,希望对你有一定的参考价值。
1、下载安装包
http://dev.mysql.com/downloads/mysql/#downloads
推荐下载通用安装方法的TAR包(http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar)。
http://dev.mysql.com/downloads/mysql/#downloads
推荐下载通用安装方法的TAR包(http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.12-linux-glibc2.5-x86_64.tar)。
2.看看自己安装过mysql;安装过则删除
[[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 [[email protected] ~]#
3.创建mysql用户及组
[[email protected] ~]#groupadd mysql [[email protected] ~]#useradd -r -g mysql mysql
之后可以查看一下成功创建没
[[email protected] ~]# cat /etc/group | grep mysql
[[email protected] ~]# cat /etc/passwd | grep mysql4.
当然首先将mysql的。tar.gz包拖到对应的目录,使用winscp工具
[[email protected] local]# tar -zxvf mysql-5.7.15-linux-glibc2.5-i686.tar.gz
5. 解压成功后将文件改个名字
[[email protected] local]# mv mysql-5.7.15-linux-glibc2.5-i686 mysql
6.安装和初始化数据库
[[email protected] local]# mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
[[email protected] local]# cd mysql
[[email protected] local]#
----------------------
如果改变默认安装路径,则需要
1)/etc/my.cnf、/etc/init.d/mysqld中修改
basedir=‘/apps/mysql‘
datadir=‘/apps/mysql/data‘
2)创建ln
mkdir -p /usr/local/mysql/bin
ln -s /apps/mysql/bin/mysqld /usr/local/mysql/bin/mysqld
----------------------
如果改变默认安装路径,则需要
1)/etc/my.cnf、/etc/init.d/mysqld中修改
basedir=‘/apps/mysql‘
datadir=‘/apps/mysql/data‘
2)创建ln
mkdir -p /usr/local/mysql/bin
ln -s /apps/mysql/bin/mysqld /usr/local/mysql/bin/mysqld
----------------------
[[email protected] mysql]#cp -a ./support-files/my-default.cnf /etc/my.cnf
问你是否覆盖时,yes
[[email protected] local]#cp -a ./support-files/mysql.server /etc/init.d/mysqld
[[email protected] mysql]# cd bin/
[[email protected] bin]# ./mysqld_safe --user=mysql &
[1] 1986
[[email protected] bin]# 2016-10-05T16:34:17.548875Z mysqld_safe Logging to ‘/usr/local/mysql/data/promote.cache-dns.local.err‘.
2016-10-05T16:34:17.629041Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[[email protected] bin]# /etc/init.d/mysqld restart Shutting down MySQL..2016-10-05T16:35:37.679390Z mysqld_safe mysqld from pid file /usr/local/mysql/data/promote.cache-dns.local.pid ended [ OK ] Starting MySQL. [ OK ] [1]+ Done ./mysqld_safe --user=mysql [[email protected] bin]#
设置开机启动mysql
[[email protected] bin]# chkconfig --level 35 mysqld on
mysql5.7会生成一个初始密码,用来登陆的
[[email protected] bin]# cat /root/.mysql_secret
# Password set for user ‘[email protected]‘ at 2016-10-06 00:29:51
Lfu+t9hi+ojn
[[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.15
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)
8.添加远程访问权限
mysql> use mysql; mysql> update user set host = ‘%‘ where user = ‘root‘; mysql>quit [[email protected] bin]# /etc/init.d/mysqld restart
9.开放端口3306(也可以用其他端口)
[[email protected] bin]#/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT;
[[email protected] bin]#/etc/init.d/iptables status
[[email protected] bin]#/etc/rc.d/init.d/iptables save
以上是关于linux下的mysql安装的主要内容,如果未能解决你的问题,请参考以下文章