Linux 服务器安装MySQL

1. Mysql的下载

a. 官网  http://dev.mysql.com/downloads/mysql/5.6.html#downloads

技术分享

   

b. 下载跟OS对应的mysql

[root@localhost ~]# uname –a                           注:查看Linux版本信息,我这里是64Linux系统

Linux localhost.localdomain 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

c. 在下拉列表选择Linux-Generic,下载64位的安装包

技术分享

   

2. Mysql的安装

a. 将下载好的mysql制作成光盘镜

不清楚的可以参考文章  Linux 下安装JDK并测试开发"Hello World"

b. 解压缩tar

[root@localhost MySQL]# tar -xvf MySQL-5.6.24-1.linux_glibc2.5.x86_64.rpm-bundle.tar
MySQL-shared-compat-5.6.24-1.linux_glibc2.5.x86_64.rpm
MySQL-test-5.6.24-1.linux_glibc2.5.x86_64.rpm
MySQL-devel-5.6.24-1.linux_glibc2.5.x86_64.rpm
MySQL-client-5.6.24-1.linux_glibc2.5.x86_64.rpm
MySQL-embedded-5.6.24-1.linux_glibc2.5.x86_64.rpm
MySQL-server-5.6.24-1.linux_glibc2.5.x86_64.rpm
MySQL-shared-5.6.24-1.linux_glibc2.5.x86_64.rpm

  

加压缩后这里有好几个rpm,我们只要安装如下两个包即可

MySQL-server-5.6.24-1.linux_glibc2.5.x86_64.rpm

MySQL-client-5.6.24-1.linux_glibc2.5.x86_64.rpm

c. 更改安装包权

解压缩后的安装包只有读写的权限,需要将其更改为可读可写可执

[root@localhost MySQL]# ll
total 622244
-rwxr--r--. 1 root root  316661760 May 26 02:11 MySQL-5.6.24-1.linux_glibc2.5.x86_64.rpm-bundle.tar
-rw-r--r--. 1 7155 wheel  23066213 Mar 26 03:57 MySQL-client-5.6.24-1.linux_glibc2.5.x86_64.rpm
-rwxr--r--. 1 root root    3848304 May 26 02:11 mysql-connector-java-5.1.35.tar.gz
-rw-r--r--. 1 7155 wheel   4571173 Mar 26 03:57 MySQL-devel-5.6.24-1.linux_glibc2.5.x86_64.rpm
-rw-r--r--. 1 7155 wheel 117570910 Mar 26 03:57 MySQL-embedded-5.6.24-1.linux_glibc2.5.x86_64.rpm
-rw-r--r--. 1 7155 wheel  88668065 Mar 26 03:58 MySQL-server-5.6.24-1.linux_glibc2.5.x86_64.rpm
-rw-r--r--. 1 7155 wheel   2410130 Mar 26 03:59 MySQL-shared-5.6.24-1.linux_glibc2.5.x86_64.rpm
-rw-r--r--. 1 7155 wheel   5180642 Mar 26 03:59 MySQL-shared-compat-5.6.24-1.linux_glibc2.5.x86_64.rpm
-rw-r--r--. 1 7155 wheel  75180190 Mar 26 03:59 MySQL-test-5.6.24-1.linux_glibc2.5.x86_64.rpm

[root@localhost Linux]# chmod 744 -R MySQL
[root@localhost Linux]# cd MySQL/

[root@localhost MySQL]# ll
total 622244
-rwxr--r--. 1 root root  316661760 May 26 02:11 MySQL-5.6.24-1.linux_glibc2.5.x86_64.rpm-bundle.tar
-rwxr--r--. 1 7155 wheel  23066213 Mar 26 03:57 MySQL-client-5.6.24-1.linux_glibc2.5.x86_64.rpm
-rwxr--r--. 1 root root    3848304 May 26 02:11 mysql-connector-java-5.1.35.tar.gz
-rwxr--r--. 1 7155 wheel   4571173 Mar 26 03:57 MySQL-devel-5.6.24-1.linux_glibc2.5.x86_64.rpm
-rwxr--r--. 1 7155 wheel 117570910 Mar 26 03:57 MySQL-embedded-5.6.24-1.linux_glibc2.5.x86_64.rpm

d. 安装Mysql-server

[root@localhost MySQL]# rpm -ivh MySQL-server-5.6.24-1.linux_glibc2.5.x86_64.rpm

Preparing... ########################################### [100%]

file /usr/share/mysql/charsets/README from install of MySQL-server-5.6.24-1.linux_glibc2.5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64

file /usr/share/mysql/czech/errmsg.sys from install of MySQL-server-5.6.24-1.linux_glibc2.5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64

file /usr/share/mysql/danish/errmsg.sys from install of MySQL-server-5.6.24-1.linux_glibc2.5.x86_64 conflicts with file from package mysql-libs-5.1.71-1.el6.x86_64

......

注:上面的报错信息意思是要安装的文件 MySQL-server-5.6.24-1.linux_glibc2.5.x86_64和系统文件mysql-libs-5.1.71-1.el6.x86_64有冲突

解决办法如下:

先查看系统下有哪些包含MySQL字符串的包,再把查到的mysql-libs-*这个包卸载掉。

[root@localhost ~]# rpm -qa |grep -i mysql                          注:查看系统下有哪些包含MySQL字符串的包

mysql-libs-5.1.71-1.el6.x86_64

[root@localhost ~]#

[root@localhost ~]# rpm -ev --nodeps mysql-libs-5.1.71-1.el6.x86_64               注:卸载mysql-libs-5.1.71-1.el6.x86_64

   

[root@localhost ~]# cd /root/Linux/MySQL/

[root@localhost MySQL]# ls

MySQL-5.6.24-1.linux_glibc2.5.x86_64.rpm-bundle.tar

MySQL-client-5.6.24-1.linux_glibc2.5.x86_64.rpm

mysql-connector-java-5.1.35.tar.gz

MySQL-devel-5.6.24-1.linux_glibc2.5.x86_64.rpm

MySQL-embedded-5.6.24-1.linux_glibc2.5.x86_64.rpm

MySQL-server-5.6.24-1.linux_glibc2.5.x86_64.rpm

MySQL-shared-5.6.24-1.linux_glibc2.5.x86_64.rpm

MySQL-shared-compat-5.6.24-1.linux_glibc2.5.x86_64.rpm

MySQL-test-5.6.24-1.linux_glibc2.5.x86_64.rpm

[root@localhost MySQL]# rpm -ivh MySQL-server-5.6.24-1.linux_glibc2.5.x86_64.rpm                             注:安装MySQL-server

Preparing... ########################################### [100%]

1:MySQL-server ########################################### [100%]

2015-05-26 03:50:44 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2015-05-26 03:50:44 0 [Note] /usr/sbin/mysqld (mysqld 5.6.24) starting as process 2931 ...

2015-05-26 03:50:44 2931 [Note] InnoDB: Using atomics to ref count buffer pool pages

2015-05-26 03:50:44 2931 [Note] InnoDB: The InnoDB memory heap is disabled

2015-05-26 03:50:44 2931 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

……

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !

You will find that password in ‘/root/.mysql_secret‘.                                 注:root用户的mysql密码在这个文件中‘/root/.mysql_secret‘,第一次连接Mysql必须更改密码

You must change that password on your first connect,

no other statement but ‘SET PASSWORD‘ will be accepted.

See the manual for the semantics of the ‘password expired‘ flag.

e. 安装MySQL-Client

[root@localhost MySQL]# rpm -ivh MySQL-client-5.6.24-1.linux_glibc2.5.x86_64.rpm

Preparing... ########################################### [100%]     

package MySQL-client-5.6.24-1.linux_glibc2.5.x86_64 is already installed

[root@localhost MySQL]#


-rwxr--r--. 1 7155 wheel  88668065 Mar 26 03:58 MySQL-server-5.6.24-1.linux_glibc2.5.x86_64.rpm
-rwxr--r--. 1 7155 wheel   2410130 Mar 26 03:59 MySQL-shared-5.6.24-1.linux_glibc2.5.x86_64.rpm
-rwxr--r--. 1 7155 wheel   5180642 Mar 26 03:59 MySQL-shared-compat-5.6.24-1.linux_glibc2.5.x86_64.rpm
-rwxr--r--. 1 7155 wheel  75180190 Mar 26 03:59 MySQL-test-5.6.24-1.linux_glibc2.5.x86_64.rpm

f. 创建mysql

[root@localhost MySQL]# groupadd mysql

创建mysql用户,并添加到mysql组中

[root@localhost MySQL]# useradd -g mysql mysql

  

g. 查看root

[root@localhost mysql]# more /root/.mysql_secret

# The random password set for the root user at Tue May 26 03:50:49 2015 (local time

): fB0j9h3IOFdT9nf5                                            注:初始密码,fB0j9h3IOFdT9nf5

h. 查看MySQL的安装目录

[root@localhost mysql]# whereis mysql

mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

i. 查看Mysql的运行目

[root@localhost MySQL]# which mysql
/usr/bin/mysql

3. 启动MySQL

a. 启动Mysql

[root@localhost MySQL]# service mysql start
Starting MySQL SUCCESS!

   

b. 查看Mysql是否启

[root@localhost MySQL]# ps -ef | grep mysql
root       1904      1  0 18:53 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.localdomain.pid
mysql      2032   1904  0 18:53 ?        00:00:09 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/localhost.localdomain.err --pid-file=/var/lib/mysql/localhost.localdomain.pid
root       3797   2874  0 20:05 pts/0    00:00:00 grep mysql

  

usr/bin/mysql 是指:mysql的运行路径
var/lib/mysql
是指:mysql数据库文件的存放路径
usr/lib/mysql
是指:mysql的安装路径

c. 查看正在运行的端口

[root@localhost mysql]# netstat -anp |more

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address Foreign Address State

PID/Program name

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN

1846/sshd

tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN

1668/cupsd

tcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN

1826/snmpd

tcp 0 0 :::22 :::* LISTEN

1846/sshd

tcp 0 0 ::1:631 :::* LISTEN

1668/cupsd

tcp 0 0 :::3306 :::* LISTEN                      3306Mysql默认的端口号

2004/mysqld

udp 0 0 0.0.0.0:631 0.0.0.0:*

......

d. 首次启动Mysql

[root@localhost mysql]# more /root/.mysql_secret         root用户的mysql初始密码

# The random password set for the root user at Tue May 26 03:50:49 2015 (local time

): fB0j9h3IOFdT9nf5

[root@localhost mysql]# mysql -h node2 -uroot -pfB0j9h3IOFdT9nf5

Warning: Using a password on the command line interface can be insecure.

ERROR 2005 (HY000): Unknown MySQL server host ‘node2‘ (111) 报错                注:找不到node2

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

于是重改密码!

# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit

# /etc/init.d/mysqld restart
# mysql -uroot -p
Enter password:

mysql>

搞定!

mysql安装过程中出现错误ERROR 1820 (HY000): You must SET PASSWORD before executing this statement解决

mysql>  SET PASSWORD = PASSWORD('123456');
Query OK, 0 rows affected (0.03 sec)
mysql> create database roger;
Query OK, 1 row affected (0.00 sec)
也就是用mysql>  SET PASSWORD = PASSWORD('123456');这句话重新设置一次密码!

                         

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值