1、下载
https://downloads.mysql.com/archives/community/
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz
2、解压并拷贝到自定义目录(/usr/local)
tar -zxvf mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz
sudo cp -r mysql-5.5.62-linux-glibc2.12-x86_64 /usr/local/mysql
cd /usr/local/mysql
3、安装MySQL
sudo chmod 750 mysql-files
sudo chown -R mysql .
sudo chgrp -R mysql .
my.cnf
[mysql] #客户端默认字符集 default-character-set=utf8 [mysqld] #设置端口 port = 3306 #安装目录 basedir=/usr/local/mysql #数据的存放目录 datadir=/usr/local/mysql/data #最大连接数 max_connections=200 # 默认字符集 character-set-server=utf8 #默认存储引擎 default-storage-engine=INNODB
vim /etc/profile #在文件的末尾添加内容:
PATH=$PATH:/usr/local/mysqlbin
export PATH
sudo ln -s /usr/local/mysql/my.cnf /etc/my.cnf
sudo ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
继而,添加服务自启动
update-rc.d mysql defaults
update-rc.d mysql enable
#查看服务状态
sudo service mysql status
#服务启动
sudo service mysql start
#服务停止
sudo service mysql stop
启动服务后设置root密码:sudo mysqladmin -u root password "123456";
设置mysql 远程登录
mysql -uroot -p123456 mysql> use mysql; mysql>select host,user,password from user; mysql> update user set password=password('123456') where user='root'; mysql> update user set host='%' where user='root' and host='localhost'; mysql> flush privileges;
如果还是无法使用IP登录MySQL,就可以考虑使用下面方法
第一种
1、停止MySQL服务,输入命令 “ sudo service mysql stop ”。
2、跳过MySQL的安全验证进行登录,输入命令 “ sudo mysqld --user=mysql --skip-grant-tables --skip-networking & ” ;然后再输入命令 “ mysql -u root -p ” 登录到MySQL,注意这儿直接回车即可,不用输入命令,如下图:
3、先进入到MySQL数据库,输入命令 “ use mysql; ” ,
然后再输入命令 “ update user set authentication_string=password('123456') where user='root'; ” 进行修改,
修改完成后,还需要刷新一下,输入命令 “ flush privileges; ” ,如下图:
第二种
登录mysql
/usr/local/mysql/bin/mysql -u root -p123456
重置root密码
set password=password(“123456”);
登录授权
GRANT ALL PRIVILEGES ON *.* TO '用户名'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
https://blog.csdn.net/weixin_38882779/article/details/105659001?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&spm=1001.2101.3001.4242
https://blog.csdn.net/Hello_World_QWP/article/details/79536037
https://www.cnblogs.com/cnblogsfans/archive/2009/09/21/1570942.html
https://www.cnblogs.com/luminji/archive/2018/10/10/9767086.html