Ubuntu安装mysql
一、环境
阿里云服务器,Ubuntu 14.04.5 LTS
mysql版本:5.5.62
二、原有mysql卸载
dpkg --remove mysql-server
dpkg --remove mysql-client
apt-get purge -f mysql-server mysql-common
rm /var/lib/mysql/ -R
rm /etc/mysql/ -R
apt-get autoremove mysql* --purge
apt-get remove apparmor
三、安装mysql
通过apt-get方式安装
apt-get install mysql-server
安装过程提示设置密码
mysql-server安装完成并运行
apt-get install mysql-client
查看mysql运行状态
service mysql status
四、连接mysql服务器
mysql命令,常用选项介绍
-p, --password[=name]
Password to use when connecting to server. If password is
not given it's asked from the tty.
-u, --user=name User for login if not current user.
-h, --host=name Connect to host.
mysql -uroot -p
输入安装时配置密码
五、密码重置或修改
密码若忘了,可以先跳过输入密码阶段,进入数据库重置密码,步骤如下:
1、跳过输入密码,进入mysql;
/etc/init.d/mysql stop
mysqld_safe --skip-grant-tables &
mysql -uroot
2、查看/配置新密码
show databases;
use mysql
查看用户、密码
mysql> select user,host,password from user
配置新密码
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root' and host='root' or host='localhost';
mysql> FLUSH PRIVILEGES;
退出mysql,重新启动: /etc/init.d/mysqld restart
修改完成。