Linux下安装Mysql

1 准备工作                           

2 安装Mysql需要的依赖

2.1 安装 Mysql
3 常用命令
3.1 验证原有主机是否已安装
3.2 启动
3.3 登录
3.4 远程登录
3.5 重启服务
3.6 停止服务
3.7 查看服务状态
4 错误解决方案
1 准备工作

本文档是在ubuntu14.04下安装5.6版本的mysql。
1.所用软件:Ubuntu14.04
2.建议使用root用户
3.使用服务器地址:192.168.1.236
4.安装mysql5.6.19
2 安装Mysql需要的依赖
安装mysql需要依赖,不然启动失败
apt-get install mysql-client-core-5.6
apt-get install mysql-client-5.6
2.1 安装 Mysql
如果运行如上命令后,在命令行信息最后看到类似
apt-get install mysql-server-5.6
安装过程中输入root的密码即可;

 

3 常用命令
3.1 验证原有主机是否已安装
这里主要是运行sudo netstat -tap | grep mysql命令查看是否有MySQL的端口,如果不加sudo的话因为权限无法顺利执行:

netstat -tap | grep mysql

3.2 启动

# 启动MySQL$ sudo service mysql start 
# 关闭MySQL$ sudo service mysql stop
# 重启MySQL$ sudo service mysql restart
# 其他命令:$ sudo /etc/init.d/mysql start
$ sudo /etc/init.d/mysql stop
$ sudo /etc/init.d/mysql restart

 然后,再次键入命令来检查是否已启动MySQL:
$ netstat -tap | grep mysql
 MySQL监听在localhost,说明MySQL已经启动。
3.3 登录
 使用命令行mysql -u root -p 来登录MySQL:
$ mysql -u root -p
3.4 远程登录
$ mysql  -h192.168.1.160 -u root -p
3.5 重启服务

sudo service mysql restart

3.6 停止服务
sudo service mysql stop
3.7 查看服务状态

sudo service mysql status 

4 错误解决方案
====================================================================================
错误:【期间安装mysql一般会报这个错误】
E: Sub-process /usr/bin/dpkg returned an error code (1)

要求设置2次root密码后 就出现这样的错误如下:
After this operation, 0 B of additional disk space will be used.
Setting up mysql-server-5.5 (5.5.28-0ubuntu0.12.04.2) ...
121209 0:30:00 [Note] Plugin 'FEDERATED' is disabled.
121209 0:30:00 InnoDB: The InnoDB memory heap is disabled
121209 0:30:00 InnoDB: Mutexes and rw_locks use GCC atomic builtins
121209 0:30:00 InnoDB: Compressed tables use zlib 1.2.3.4
121209 0:30:00 InnoDB: Initializing buffer pool, size = 128.0M
121209 0:30:00 InnoDB: Completed initialization of buffer pool
121209 0:30:00 InnoDB: highest supported file format is Barracuda.
121209 0:30:00 InnoDB: Waiting for the background threads to start
121209 0:30:01 InnoDB: 1.1.8 started; log sequence number 1595675
121209 0:30:01 InnoDB: Starting shutdown...
121209 0:30:01 InnoDB: Shutdown completed; log sequence number 1595675
AppArmor parser error for /etc/apparmor.d/usr.sbin.mysqld in /etc/apparmor.d/usr.sbin.mysqld at line 9: Could not open 'abstractions/mysql'
start: Job failed to start
invoke-rc.d: initscript mysql, action "start" failed.
dpkg: error processing mysql-server-5.5 (--configure):
subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
mysql-server depends on mysql-server-5.5; however:
Package mysql-server-5.5 is not configured yet.
dpkg: error processing mysql-server (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Errors were encountered while processing:
mysql-server-5.5
mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)


解决方法:

用命令 sudo apt-get install mysql-server


卸载Mysql:
sudo apt-get autoremove mysql* --purge
sudo apt-get remove apparmor
sudo apt-get install mysql-server mysql-common
删除mysql前‘ 记得删除一下 /var/lib/mysql 还有 /etc/mysql【总之查看一下mysql的路径,然后删除所有跟mysql的文件,目的就是卸载完全】


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。