一、安装apt-get install mysql-server 需要设置账号密码
apt-get isntall mysql-client
apt-get libmysqlclient-dev2.sudo netstat -tap | grep mysql 查看是否安装成功
[email protected]:~# netstat -tap | grep mysql tcp6 0 0 [::]:mysql [::]:* LISTEN 7510/mysqld -->安装成功
二、设置mysql远程访问
1. 编辑mysql配置文件,把其中bind-address = 127.0.0.1注释了
vi /etc/mysql/mysql.conf.d/mysqld.cnf
2. 使用root进入mysql命令行,执行如下2个命令,示例中mysql的root账号密码:root
grant all on *.* to [email protected]‘%‘ identified by ‘root‘ with grant option; flush privileges;
3. 重启mysql
/etc/init.d/mysql restart
三、MySQL修改root密码的多种方法
方法1: 用SET PASSWORD命令
mysql -u root mysql> SET PASSWORD FOR ‘root‘@‘localhost‘ = PASSWORD(‘newpass‘);
方法2:用mysqladmin
mysqladmin -u root password "newpass" 如果root已经设置过密码,采用如下方法 mysqladmin -u root password oldpass "newpass"
方法3: 用UPDATE直接编辑user表
mysql -u root mysql> use mysql; mysql> UPDATE user SET Password = PASSWORD(‘newpass‘) WHERE user = ‘root‘; mysql> FLUSH PRIVILEGES;
在丢失root密码的时候,可以这样
mysqld_safe --skip-grant-tables&
mysql -u root mysql
mysql> UPDATE user SET password=PASSWORD("new password") WHERE user=‘root‘;
mysql> FLUSH PRIVILEGES;
时间: 2024-11-05 14:51:48