Mysql安装有两种方式一种是在线联网安装,一种是离线安装
1、联网安装:
安装依赖包
sudo apt-get install cmakesudo apt-get install libncurses5-dev
安装mysql
sudo apt-get install mysql-serversudo apt-get isntall mysql-clientsudo apt-get install libmysqlclient-dev
查看是否安装成功:
sudo netstat-tap|grep mysql
通过上述命令检查之后,如果看到有mysql 的socket处于 listen 状态则表示安装成功。
tcp00localhost:mysql*:*LISTEN1320/mysqld
登陆mysql数据库
mysql-u root-p
查看mysql版本
mysqladmin-u root-p version
停止mysql:
sudo service mysql stop
启动mysql:
sudo service mysql start
二、离线安装mysql
下载mysql安装包
我这里下载的是mysql-5.5.50-linux2.6-x86_64.tar.gz 这个版本
1、解压并移动到/usr/local/mysql
tar-zxvf mysql-5.5.50-linux2.6-x86_64.tar.gzsudo mv mysql-5.5.50-linux2.6-x86_64/usr/local/mysql
2、添加用户组,赋权限
groupadd mysqluseradd-r-g mysql mysqlsudo chown-R mysql:mysql mysql
接着进入mysql目录,修改mysql目录的拥有者,为mysql用户:
cd/usr/local/mysqlsudo chown-R mysql.sudo chgrp-R mysql.
3、安装数据库
/usr/local/mysql$ sudo scripts/mysql_install_db--user=mysql
fulong@FBI003:/usr/local/mysql$ sudo scripts/mysql_install_db--user=mysqlInstallingMySQLsystem tables...16070416:14:03[Note]./bin/mysqld(mysqld5.5.50)starting as process7089...OKFillinghelp tables...16070416:14:03[Note]./bin/mysqld(mysqld5.5.50)starting as process7095...OKTostart mysqld at boot time you have to copysupport-files/mysql.server to the right placeforyour systemPLEASE REMEMBER TO SET A PASSWORD FOR THEMySQLroot USER!Todoso,start the server,thenissue the following commands:./bin/mysqladmin-u root password'new-password'./bin/mysqladmin-u root-h FBI003 password'new-password'Alternativelyyou can run:./bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default.Thisisstrongly recommendedforproduction servers.Seethe manualformore instructions.Youcan start theMySQLdaemon with:cd.;./bin/mysqld_safe&Youcan test theMySQLdaemon with mysql-test-run.plcd./mysql-test;perl mysql-test-run.plPleasereport any problems at http://bugs.mysql.com/
如果有如下报错
InstallingMySQLsystem tables..../bin/mysqld:errorwhileloading shared libraries:libaio.so.1:cannot open shared object file:Nosuch file or directory
则需要安装有一个依赖包
sudo apt-get install libaio-dev
4、启动mysql
sudo./support-files/mysql.server start
如下错误:
StartingMySQL..*Theserver quit without updating PID file(/usr/local/mysql/data/FBI003.pid).
看下是否有启动的进程
root@FBI003:/usr/local/mysql# ps -aux|grep mysqlmysql51450.01.142692847160?Ssl15:440:02/usr/sbin/mysqldroot86300.00.011072680pts/0S+16:500:00grep--color=auto mysq
若有 kill掉,没有的话 考虑是否权限不对
设置mysql用户组权限
chown-R mysql data
5、修改初始密码
./bin/mysqladmin-u root password'fulong'
6、进入数据库
root@FBI003:/usr/local/mysql/bin# ./mysql -u root -p
7、为了方便期间,可以配置环境变量,直接使用mysql命令
sudo vim/etc/profileexport MYSQL_HOME=/usr/local/mysqlexport PATH=$MYSQL_HOME/bin:$PATH
source/etc/profile
8、添加mysql自启动
复制到init.d
sudo cp/usr/local/mysql/support-files/mysql.server/etc/init.d/mysqlfulong@FBI003:/usr/local/mysql$
赋权限
sudo chmod+x/etc/init.d/mysql
设置自启动
sudo update-rc.d mysql defaults
移除自启动
update-rc.d mysql remove
9、修改配置文件(可不做修改)
修改mysql最大连接数:
cp support-files/my-medium.cnf./my.cnf,vim my.cnf,增加或修改max_connections=1024
关于my.cnf:mysql按照下列顺序搜索my.cnf:/etc,mysql安装目录,安装目录下的data。/etc下的是全局设置。
注意:
修改数据库远程模式
1、所有主机都能登录
grant all privileges on*.*to root@"%"identified by"fulong"with grant option;
2、指定主机登录
grant all privileges on*.*to root@"192.168.0.101"identified by"fulong"with grant option;flush privileges;
3、进mysql库查看host为%的数据是否添加:
use mysql;select user,hostfrom user;
查看日志状态
show variables like'log_%';
创建数据库:
1) 建库:create database hivedb;
2) 建用户,赋权:grant all privileges on *.* to hivedb@"%" identified by "hivedb" with grant option;
3) 删除数据库:drop database hivedb;
查看数据库:
show databases;
查看当前字符集:
show variables like 'character%';
**************************************************************
启动mysql: 使用命令试试是否能连上mysql
telnet 192.168.0.166 3306
若拒绝连接 编辑
sudo vim /etc/mysql/my.cnf
注释掉
#bind-address = 127.0.0.1
即可