当前位置:首页 > 服务器 > 正文

关于在阿里云linux服务器上安装mysql的信息

本篇文章给大家谈谈在阿里云linux服务器上安装mysql,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

linux服务器上怎么安装mysql

安装包:mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz

使用xshell连接linux服务器,使用root用户名登录,依次执行以下命令:

======================================================

/usr/sbin/groupadd mysql 【添加mysql组】

/usr/sbin/useradd -d /var/lib/mysql -s /sbin/nologin -g mysql mysql

mkdir -p /usr/local/src/mysql 【新建mysql文件夹】

cd / 【打开上传安装包的目录】

mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz 【上传安装包到服务器的根目录下】

mv mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz /usr/local/src/mysql【根目录的安装包移动到文件夹下】

cd /usr/local/src/mysql【打开目录】

tar -zxvf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz【解压安装包】

cp mysql-5.6.30-linux-glibc2.5-x86_64 /usr/local/mysql -r【复制文件】

cd /usr/local【打开目录】

chown -R mysql:mysql mysql/

cd /usr/local/mysql/scripts/【打开目录】

./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data【执行脚本】

cd /usr/local/mysql/support-files【打开目录】

cp my-default.cnf /etc/my.cnf【复制文件到新的路径下及文件名】

cp: overwrite `/etc/my.cnf'?Y【Y】

cp mysql.server /etc/init.d/mysql【复制文件到新的路径下】

vim /etc/profile【编辑软件运行环境】

vim i(编辑一些内容) esc(进入normal) w(保存文件) q(不保存退出文件)

###############################################################

export MYSQL_HOME=/usr/local/mysql

export PATH=$MYSQL_HOME/bin:$PATH

###############################################################

source /etc/profile

chkconfig --add mysql

chkconfig mysql on

service mysql start

/usr/local/mysql/bin/mysqladmin -u root password 'rootroot'【修改数据库root的密码】

grant all privileges on tdcdb.* to 'root'@'%' identified by 'rootroot' 【给mysql用户分配权限】

flush privileges;

vim /etc/sysconfig/iptables【编辑访问端口号】

###############################################################

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT(添加3306的端口号)

###############################################################

service iptables restart

netstat -ntlp

mysql -u root -p (命令未找到使用: ln -s /usr/local/mysql/bin/mysql /usr/bin)

create user 'tdc'@'%' identified by 'P@ssw0rd';【创建数据库访问用户】

create database if not exists `tdcdb`;【创建数据库】

grant all privileges on tdcdb.* to 'tdc'@'%' identified by 'P@ssw0rd';【给tdc用户分配访问密码】

flush privileges;

vi /etc/my.cnf【编辑配置文件,支持语言设置】

###############################

[client]

default-character-set=utf8

[mysqld]

character-set-server=utf8

[mysql]

default-character-set=utf8

###############################

service mysql stop【重新启动mysql服务】

service mysql start

======================================================

linux 常用命令:

pwd:查看当前路径

ll:2个小写的L,查看当前目录下的所有文件

cd:打开目录,包括路径地址及文件夹

vi 文件名:编辑linux下的文件,使用大写的【I】命令来进行编辑,编辑完成后点击【ESC】按钮跳出编辑,输入【:wq!】命令来退出保存;

注意:linux的文件不能打开直接修改,只能通过vi命令进行修改

======================================================

卸载程序的方式:

ps -ef | grep mysql

/etc/init.d/mysql status

whereis mysql

find / -name mysql【找到所有文件名为mysql的文件列表】

rm -rf /usr/local/mysql/【使用rm命令来移除列表中的文件】

rm -rf /etc/my.cnf【使用rm命令来移除列表中的文件】

阿里云服务器怎么安装mysql数据库步骤

如果是Windows的主机,我建议你安装网站管理助手,环境检测里面选择后会自动安装,百度搜索下载。如果是Linux的主机,安装WDCP,安装完成本身就集成了mysql,并且有web管理面板,使用很方便。

如何在云服务器上安装mysql

说说我在阿里云服务器上安装mysql的心路历程吧,刚开始安装好java8和tomcat8,安装非常的顺利,但是我接下来要安装mysql了,在网上看到一篇帖子(是rpm包安装的,也在本机上的centos6.5安装过没有问题),所以我就按照这个安装mysql,可是失败了,报错了。

然后在网上疯狂的找解决方法,然后卸载后重装,装了又卸,折腾的只剩半条命了,然后网上又说要源码安装,所以我又下载mysql的.tar.gz包,然后这样安装,但是如上图显示,但是原来的错误,我就在想是不是内存太小的原因,但是想想又不对,因为别人怎么又安装成功了,心有不甘啊!然后找阿里管理人员,他说我重装好多次要重置系统盘,好,我重置系统盘了,然后重新编译安装,安装好后,出现相同问题,tmd我真想骂人了。

最后我找到阿里云服务器上帮助一篇文章“一键安装web环境”安装好mysql,这次成功了,但是远程登录不了,无奈我又叫他们的管理人员帮我看看,然后就可以远程登录了,我也不知道他们怎么搞好的,不过他登录的是我的服务器,所以可以用history命令查看他的操作,结果如下:

81 ps aux

82 history

83 cd /var/opt/

84 ls

85 cd

86 ls

87 cd /tmp/

88 ls

89 cd /home/

90 ls

91 cd sh-1.3.0/

92 ls

93 more account.log

94 /alidata/server/mysql/bin/mysql -u root -p

95 service mysqld r

如何在linux中安装mysql

1.首先在liunx下安装Mysql数据库

~$ sudo apt-get install mysql-server #安装Mysql服务器端

~$ ps -aux|grep mysql #检查Mysql服务器进程

beili 10301 0.0 0.0 37080 3604 pts/7 S+ 5月20 0:00 mysql -u root -p

mysql 25125 0.0 0.0 4472 1704 ? Ss 09:51 0:00 /bin/sh /usr/bin/mysqld_safe

mysql 25496 0.0 3.1 859956 127084 ? Sl 09:51 0:01 /usr/sbin/mysqd --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306

beili 26652 0.0 0.0 13708 2180 pts/19 S+ 10:32 0:00 grep --color=auto mysql

~$ netstat -nlt|grep 3306 #检查Mysql服务器占用端口

tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN

~$ /etc/init.d/mysql status # 通过启动命令检查Mysql服务器状态

Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)

Active: active (running) since 四 2015-05-21 09:51:13 CST; 43min ago

Process: 25126 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)

Process: 25122 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)

~$ service mysql status # 通过系统服务检查Mysql服务器状态

● mysql.service - MySQL Community Server

Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)

Active: active (running) since 四 2015-05-21 09:51:13 CST; 44min ago

Process: 25126 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS)

Process: 25122 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)

~$ whereis mysql # 查看mysql各个文件安装的目录

mysql: /usr/bin/mysql /usr/lib/mysql /etc/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

2.访问和配置Mysql

$ mysql -u root -p

Enter password:

mysql默认的字符集为latin1的,所以要改为utf8的。很多网上的文章执行“sudo vi /etc/mysql/my.cnf”,可是打开一看,里面就两行话:

!includedir /etc/mysql/conf.d/

!includedir /etc/mysql/mysql.conf.d/

想来mysql的配置文件应该是在那两个文件夹下面,于是尝试之下打开了/etc/mysql/mysql.conf.d/ 下的mysqld.cnf文件,执行下面的命令:

~$ sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

...

[client]

default-character-set=utf8

[mysqld_safe]

socket = /var/run/mysqld/mysqld.sock

nice = 0

[mysqld]

character-set-server=utf8

collation-server=utf8_general_ci

...

注:棕色部分是添加的内容

重启mysql服务,并查看字符集的设置情况:

~$ sudo /etc/init.d/mysql restart

~$ mysql -u root -p

mysql show variables like "%char%"

+--------------------------+----------------------------+

| Variable_name | Value |

+--------------------------+----------------------------+

| character_set_client | utf8 |

| character_set_connection | utf8 |

| character_set_database | utf8 |

| character_set_filesystem | binary |

| character_set_results | utf8 |

| character_set_server | utf8 |

| character_set_system | utf8 |

| character_sets_dir | /usr/share/mysql/charsets/ |

linux上怎么安装mysql

1. 运行平台:CentOS 6.3 x86_64,基本等同于RHEL 6.3

2. 安装方法:

安装MySQL主要有两种方法:一种是通过源码自行编译安装,这种适合高级用户定制MySQL的特性,这里不做说明;另一种是通过编译过的二进制文件进行安装。二进制文件安装的方法又分为两种:一种是不针对特定平台的通用安装方法,使用的二进制文件是后缀为.tar.gz的压缩文件;第二种是使用RPM或其他包进行安装,这种安装进程会自动完成系统的相关配置,所以比较方便。

3. 下载安装包:

2. 下载文件(根据操作系统选择相应的发布版本):

a. 通用安装方法

mysql-5.5.29-linux2.6-x86_64.tar.gz

b. RPM安装方法:

MySQL-server-5.5.29-2.el6.x86_64.rpm

MySQL-client-5.5.29-2.el6.x86_64.rpm

4. 通用安装步骤

a. 检查是否已安装,grep的-i选项表示匹配时忽略大小写

[root@localhost JavaEE]#rpm -qa|grep -i mysql

mysql-libs-5.1.61-4.el6.x86_64

*可见已经安装了库文件,应该先卸载,不然会出现覆盖错误。注意卸:载时使用了--nodeps选项,忽略了依赖关系:

[root@localhost JavaEE]#rpm -e mysql-libs-5.1.61-4.el6.x86_64 --nodeps

b. 添加mysql组和mysql用户,用于设置mysql安装目录文件所有者和所属组。

[root@localhost JavaEE]#groupadd mysql

[root@localhost JavaEE]#useradd -r -g mysql mysql

*useradd -r参数表示mysql用户是系统用户,不可用于登录系统。

c. 将二进制文件解压到指定的安装目录,我们这里指定为/usr/local

[root@localhost ~]# cd/usr/local/

[root@localhost local]#tar zxvf /path/to/mysql-5.5.29-linux2.6-x86_64.tar.gz

*加压后在/usr/local/生成了解压后的文件夹mysql-5.5.29-linux2.6-x86_64,这名字太长,我们为它建立一个符号链接mysql,方便输入。

[root@localhost local]#ln -s mysql-5.5.29-linux2.6-x86_64 mysql

d. /usr/local/mysql/下的目录结构

Directory

Contents of Directory

bin

Client programs and the mysqld server

data

Log files, databases

docs

Manual in Info format

man

Unix manual pages

include

Include (header) files

lib

Libraries

scripts

mysql_install_db

share

Miscellaneous support files, including error messages, sample configuration files, SQL for database installation

sql-bench

Benchmarks

e. 进入mysql文件夹,也就是mysql所在的目录,并更改所属的组和用户。

[root@localhost local]#cd mysql

[root@localhost mysql]#chown -R mysql .

[root@localhost mysql]#chgrp -R mysql .

f. 执行mysql_install_db脚本,对mysql中的data目录进行初始化并创建一些系统表格。注意mysql服务进程mysqld运行时会访问data目录,所以必须由启动mysqld进程的用户(就是我们之前设置的mysql用户)执行这个脚本,或者用root执行,但是加上参数--user=mysql。

[root@localhost mysql]scripts/mysql_install_db --user=mysql

*如果mysql的安装目录(解压目录)不是/usr/local/mysql,那么还必须指定目录参数,如

[root@localhost mysql]scripts/mysql_install_db --user=mysql \

--basedir=/opt/mysql/mysql \

--datadir=/opt/mysql/mysql/data

*将mysql/目录下除了data/目录的所有文件,改回root用户所有,mysql用户只需作为mysql/data/目录下所有文件的所有者。

[root@localhost mysql]chown -R root .

[root@localhost mysql]chown -R mysql data

g. 复制配置文件

[root@localhost mysql] cp support-files/my-medium.cnf /etc/my.cnf

h. 将mysqld服务加入开机自启动项。

*首先需要将scripts/mysql.server服务脚本复制到/etc/init.d/,并重命名为mysqld。

[root@localhostmysql] cp support-files/mysql.server /etc/init.d/mysqld

*通过chkconfig命令将mysqld服务加入到自启动服务项中。

[root@localhost mysql]#chkconfig --add mysqld

*注意服务名称mysqld就是我们将mysql.server复制到/etc/init.d/时重命名的名称。

*查看是否添加成功

[root@localhost mysql]#chkconfig --list mysqld

mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

i. 重启系统,mysqld就会自动启动了。

*检查是否启动

[root@localhost mysql]#netstat -anp|grep mysqld

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2365/mysqld

unix 2 [ ACC ] STREAM LISTENING 14396 2365/mysqld /tmp/mysql.sock

*如果不想重新启动,那可以直接手动启动。

[root@localhost mysql]#service mysqld start

Starting MySQL.. SUCCESS!

j. 运行客户端程序mysql,在mysql/bin目录中,测试能否连接到mysqld。

[root@localhost mysql]#/usr/local/mysql/bin/mysql

Welcome to the MySQLmonitor. Commands end with ; or \g.

Your MySQL connection idis 2

Server version:5.5.29-log MySQL Community Server (GPL)

Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved.

Oracle is a registeredtrademark of Oracle Corporation and/or its affiliates. Other names may betrademarks of their respective owners.

Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement.

mysql quit

Bye

*此时会出现mysql命令提示符,可以输入sql语句,输入quit或exit退出。为了避免每次都输入mysql的全路径/usr/local/mysql/bin/mysql,可将其加入环境变量中,在/etc/profile最后加入两行命令:

MYSQL_HOME=/usr/local/mysql

export PATH=$PATH:$MYSQL_HOME/bin

这样就可以在shell中直接输入mysql命令来启动客户端程序了

[root@localhost mysql]#mysql

Welcome to the MySQLmonitor. Commands end with ; or \g.

Your MySQL connection idis 3

Server version:5.5.29-log MySQL Community Server (GPL)

Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved.

Oracle is a registeredtrademark of Oracle Corporation and/or its

affiliates. Other namesmay be trademarks of their respective

owners.

Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement.

mysql

5. RPM安装步骤

a. 检查是否已安装,grep的-i选项表示匹配时忽略大小写

[root@localhost JavaEE]#rpm -qa|grep -i mysql

mysql-libs-5.1.61-4.el6.x86_64

可见已经安装了库文件,应该先卸载,不然会出现覆盖错误。注意卸载时使用了--nodeps选项,忽略了依赖关系:

[root@localhost JavaEE]#rpm -e mysql-libs-5.1.61-4.el6.x86_64 --nodeps

2. 安装MySQL的服务器端软件,注意切换到root用户:

[root@localhost JavaEE]#rpm -ivh MySQL-server-5.5.29-2.el6.x86_64.rpm

安装完成后,安装进程会在Linux中添加一个mysql组,以及属于mysql组的用户mysql。可通过id命令查看:

[root@localhost JavaEE]#id mysql

uid=496(mysql)gid=493(mysql) groups=493(mysql)

MySQL服务器安装之后虽然配置了相关文件,但并没有自动启动mysqld服务,需自行启动:

[root@localhost JavaEE]#service mysql start

Starting MySQL.. SUCCESS!

可通过检查端口是否开启来查看MySQL是否正常启动:

[root@localhost JavaEE]#netstat -anp|grep 3306

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 34693/mysqld

c. 安装MySQL的客户端软件:

[root@localhost JavaEE]#rpm -ivh MySQL-client-5.5.29-2.el6.x86_64.rpm

如果安装成功应该可以运行mysql命令,注意必须是mysqld服务以及开启:

[root@localhost JavaEE]#mysql

Welcome to the MySQLmonitor. Commands end with ; or \g.

Your MySQL connection idis 1

Server version: 5.5.29MySQL Community Server (GPL)

Copyright (c) 2000, 2012,Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademarkof Oracle Corporation and/or its affiliates. Other names may be trademarks oftheir respective owners.

Type 'help;' or '\h' forhelp. Type '\c' to clear the current input statement.

mysql

如何在阿里云服务器上安装mysql数据库?

1首先清除51版本的多余包(有些阿里云版本系统里有残留) yum -y remove mysql-libs-51*; 2安装mysql55服务器端程序, 下载地址:7386383 rpm -ivh MySQL-server-5534-1linux26x86_64rp如何在阿里云服务器上安装mysql数据库?

关于在阿里云linux服务器上安装mysql和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

取消
扫码支持 支付码