Ubuntu下的mysql安装

出处:http://blog.chinaunix.net/uid-26275986-id-4051976.html

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

二、安装mysql
     确定没有安装mysql之后,开始运行sudo apt-get install mysql-server mysql-client来安装mysql:

     在安装的过程中会提示你输入Yes,然后会弹出root密码设置界面,这里可以先设置一个root密码作为登录mysql用户使用,之后需要的时候也可以运行mysqladmin -u root -p password进行修改密码,当然那个时候得先输入原密码了。
三、启动Mysql
     自动安装完成之后,可以再次验证安装成功:

四、修改配置文件
     在正式启动Mysql以前需要先修改一下配置文件,主要是sudo vim /etc/mysql/my.cnf下,注释掉binding-address=127.0.0.1的这句代码,其他配置根据需要灵活修改即可。
五、启动mysql     
     在命令终端上输入mysql -u root -p,然后输入密码即可登录mysql数据库:


六、关于卸载
     由于这部分自己刚刚装上,所以没有实际操作,从网上查了一些资料,整理在下面作为备用吧:
1. 打开关闭服务:/etc/init.d/mysql start/stop
2. 卸载mysql:
    sudo apt-get autoremove --purge mysql-server-5.0
   sudo apt-get remove mysql-server
   sudo apt-get autoremovemysql-server
   sudo apt-get remove mysql-common
   dpkg -l | grep ^rc| awk '{print $2}' | sudoxargsdpkg -P

七、修改root用户口令。
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set Password = PASSWORD('root') where User ='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0

mysql> exit
注意:括号里的'root'就是新密码。

原文地址:https://www.cnblogs.com/wowchky/p/4276535.html