mysql-mysql在Windows系统安装详细步骤&&mysql在linux系统的安装详细步骤

一、mysql在Windows系统安装详细步骤


网上有很多,靠谱的很少,下面附上我亲自安装体验过的几个链接,仅供参考:

https://blog.csdn.net/shenkeding9350/article/details/84889562

https://blog.csdn.net/bobo553443/article/details/81383194

二、 mysql在linux系统的安装详细步骤


一、安装步骤

1、确认当前虚拟机之前是否有安装过mysql

查看linux安装过的所有rpm包
执行:rpm -qa | grep mysql 

如果出现下图,证明已经安装了mysql,需要删除

[root@hadoop01 ~]# rpm -qa | grep mysql
mysql-libs-5.1.71-1.el6.x86_64
[root@hadoop01 ~]# 

 

2、删除mysql

执行:rpm -ev --nodeps mysql-libs-5.1.71-1.el6.x86_64

此时,再执行:rpm -qa | grep mysql  发现没有相关信息了

[root@hadoop01 ~]# rpm -ev --nodeps mysql-libs-5.1.71-1.el6.x86_64
[root@hadoop01 ~]# rpm -qa | grep mysql
[root@hadoop01 ~]# 
3、新增mysql用户组,并创建mysql用户

       groupadd mysql     useradd -r -g mysql mysql

我的linux中因为之前已经创建过,所以提示已经存在

[root@hadoop01 ~]# groupadd mysql
groupadd: group 'mysql' already exists
[root@hadoop01 ~]# useradd -r -g mysql mysql
useradd: user 'mysql' already exists
[root@hadoop01 ~]# 
4、安装mysql server rpm包和client包,

      rpm -ivh MySQL-server-5.6.29-1.linux_glibc2.5.x86_64.rpm

      rpm -ivh MySQL-client-5.6.29-1.linux_glibc2.5.x86_64.rpm

执行:cd /home/software     在该目录下下载

      1、MySQL-client-5.6.29-1.linux_glibc2.5.x86_64.rpm

wget http://bj-yzjd.ufile.cn-north-02.ucloud.cn/MySQL-client-5.6.29-1.linux_glibc2.5.x86_64.rpm

      2、MySQL-server-5.6.29-1.linux_glibc2.5.x86_64.rpm

wget http://bj-yzjd.ufile.cn-north-02.ucloud.cn/MySQL-server-5.6.29-1.linux_glibc2.5.x86_64.rpm

[root@hadoop01 ~]# cd /home/software
[root@hadoop01 software]# wget http://bj-yzjd.ufile.cn-north-02.ucloud.cn/MySQL-client-5.6.29-1.linux_glibc2.5.x86_64.rpm

[root@hadoop01 software]# wget http://bj-yzjd.ufile.cn-north-02.ucloud.cn/MySQL-server-5.6.29-1.linux_glibc2.5.x86_64.rpm
5、安装后,mysql文件所在的目录,找到mysql相关的全部删除ls /usr/bin/mysql*
Directory        Contents of Directory
/usr/bin        Client programs and scripts
/usr/sbin        The mysqld server
/var/lib/mysql        Log files, databases
/usr/share/info        MySQL manual in Info format
/usr/share/man        Unix manual pages
/usr/include/mysql        Include (header) files
/usr/lib/mysql        Libraries
/usr/share/mysql        Miscellaneous support files, including error messages, character set files, sample configuration files, SQL for database installation

/usr/share/sql-bench        Benchmarks
6、修改my.cnf,默认在/usr/my.cnf,执行:vim /usr/my.cnf,添加如下内容:
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
character_set_server=utf8
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
7、将mysqld加入系统服务,并随机启动
执行:cp /usr/share/mysql/mysql.server   /etc/init.d/mysqld
说明:/etc/init.d 是linux的一个特殊目录,放在这个目录的命令会随linux开机而启动。
8、启动mysqld,执行:service mysqld start 然后mysql -u root -p登录发现秘密错误

 

9、查看初始生成的密码,执行:vim /root/.mysql_secret 。这个密码随机生成的,复制密码拷贝shift+Insert粘贴进去

 

10、修改初始密码, 第一次安装完mysql后,需要指定登录密码
执行:mysqladmin -u root -p  password root  此时,提示要输入初始生成的密码,拷贝过来即可
11、进入mysql数据库
执行:mysql -u root -p
输入:root进入
执行:\s查看mysql数据配置信息

二、常见问题

  1. 如果出现不能修改密码的问题,则可以执行如下命令强制修改:
    1. 关闭MySQL服务:service mysqld stop
    2. 进入安全模式:mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
    3. 在安全模式下输入:mysql -u root mysql
    4. 进入mysql之后输入:
      1. UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
      2. FLUSH PRIVILEGES;
      3. quit
    5. 重启MySQL服务:service mysqld restart
  2. 显示MySQL密码过期:
    1. 进入mysql
    2. 使用mysql库:use mysql
    3. 更新密码状态:update user set password_expired='N' where user='root';
    4. 更新策略:flush privileges;
    5. 退出MySQL:quit

猜你喜欢

转载自blog.csdn.net/weixin_47055922/article/details/108467208