Windows10
一:mysql安装包下载:https://dev.mysql.com/downloads/mysql/
二:解压
三:在bin同级下手动创建my.txt 并讲.txt修改成ini ,并在bin同级下创建data文件夹
四:配置my.ini
#### start ########################
[mysqld]
#设置3306端口
port = 3306
## 设置mysql的安装目录
basedir=C:\\mysql\\mysql-5.7.28-winx64
## 设置mysql数据库的数据data的存放目录
datadir=C:\\mysql\\mysql-5.7.28-winx64\\data
## 允许最大连接数
max_connections=200
## 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
## 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
innodb_buffer_pool_size=1024M
innodb_log_file_size=48M
sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER
#开启查询缓存
explicit_defaults_for_timestamp=true
#开启安全模式,进入mysql无需输入密码
skip-grant-tables
[client]
port=3306
default-character-set=utf8
[mysql]
default-character-set=utf8
### end ######################################
五:找到cmd.exe 已管理员身份运行,否则后续会提示无权限操作
六:进入CMD操作
1.sc delete mysql 删除以前未删除的mysql服务
Microsoft Windows [版本 10.0.17134.1]
(c) 2018 Microsoft Corporation。保留所有权利。
C:\WINDOWS\system32>sc delete mysql
[SC] DeleteService 成功
C:\WINDOWS\system32>cd C:\mysql\mysql-5.7.28-winx64\bin
C:\mysql\mysql-5.7.28-winx64\bin>mysqld -install
Service successfully installed.
C:\mysql\mysql-5.7.28-winx64\bin>mysqld --initialize --user=mysql --console
2019-11-27T06:18:35.806560Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-11-27T06:18:36.035751Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-11-27T06:18:36.135728Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: beb1193d-10dd-11ea-93c3-509a4c2ae498.
2019-11-27T06:18:36.145732Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-11-27T06:18:38.063334Z 0 [Warning] CA certificate ca.pem is self signed.
2019-11-27T06:18:38.381870Z 1 [Note] A temporary password is generated for root@localhost: ZWlO%pvQi1ny
C:\mysql\mysql-5.7.28-winx64\bin>net start mysql
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
C:\mysql\mysql-5.7.28-winx64\bin>mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
#可能报错如下
mysql> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement befo
re executing this statement.
#解决方法
mysql> ALTER USER USER() IDENTIFIED BY '123456';
mysql> update user set authentication_string='123456' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql>quit;
Liunx
一:参考链接:http://www.cnblogs.com/starof/p/4680083.html
二:mysql 安装
1、方法一:安装mariadb
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。
安装mariadb,大小59 M。
1)安装 :yum install mariadb-server mariadb
mariadb数据库的相关命令是:
systemctl start mariadb #启动MariaDB
systemctl stop mariadb #停止MariaDB
systemctl restart mariadb #重启MariaDB
systemctl enable mariadb #设置开机启动
所以先启动数据库
2)[root@yl-web yl]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.41-MariaDB MariaDB Server
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>
3)设置密码
mysql> set password for 'root'@'localhost' =password('password');
Query OK, 0 rows affected (0.00 sec)
mysql配置文件为/etc/my.cnf
最后加上编码配置
[mysql]
default-character-set =utf8
这里的字符编码必须和/usr/share/mysql/charsets/Index.xml中一致。
2、远程连接设置
把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。
mysql> grant all privileges on *.* to root@'%'identified by 'password';
如果是新用户而不是root,则要先新建用户
mysql>create user 'username'@'%' identified by 'password';
此时就可以进行远程连接了。