Reprinted https://www.cnblogs.com/wangshen31/p/9556804.html
Delete the original database:
centos7 installed by default in the database MariaDB, MySQL If you install it, will be covered directly out of the database, of course, you can delete it manually:
[Root @ localhost ~] # rpm -qa | grep mariadb // check out mariadb installed [Root @ localhost ~] # rpm -e --nodeps file name // unload mariadb, check out the file named above command file
And now the current directory to the root is: cd ~
Download and install MySQL:
Well, here using a variety of Yum dependent rpm package management, can automatically download the RPM packages from the specified server and installed, it must be relieved after installation, otherwise it will be automatically updated.
1. Install the MySQL official yum repository
[root@localhost ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
2. Download the rpm package
[root@localhost ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
3. Install the MySQL service
[root@localhost ~]# yum -y install mysql-community-server
Finally, there will be a complete!
4. Start MySQL service
[root@localhost ~]# systemctl start mysqld.service
See something like the interface, or to Starting MySqL server .. started MysqlServer .. ending successfully launched
There are several commonly used commands on MySQL:
Restart: systemctl restart mysqld.service Stop: systemctl stop mysqld.service View status: systemctl status mysqld.service
You can also configure the MySQL boot:
[root@woitumi-128 ~]# systemctl enable mysqld [Root @ woitumi-128 ~] # systemctl service daemon-reload configuration just need to be able to identify systemctl, you must refresh configuration
Log on MySQL:
Login command:
[root@localhost ~]# mysql -u root -p
Meaning that log in as root user, then prepare to enter a password.
After the first start MySQL, there will be a temporary password, the default initial password /var/log/mysqld.log file, we can use this command to view:
grep "password" /var/log/mysqld.log
But I do not know if the wrong password or can not copy and paste, has been an error:
(Well, look at the back of this code should be mysql -u root -p fishes, may enter this command would be no mistake about it ......)
Then we can skip password authentication to log into MySQL:
Out of service:
systemctl stop mysqld.service
MMySQL modify configuration files:
we /etc/my.cnf
Add the final configuration:
skip-grant-tables
And then start the service:
systemctl start mysqld.service
Then then you can skip the password to log mysql:
mysql -u root
Then the modifications Password: (see the example of others like this)
mysql> use mysql; Database changed mysql> update mysql.user set authentication_string=password('4008') where user='root' ; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1
Then exit to exit mysql, again remove the skip-grant-tables in just the configuration file, and then restart MySQL.
Then you can log in with the new password:
sql error
But this time, I tried a simple sql statement:
what? ? ? I do not have just finished setting your password? ?
Then the next Baidu. He said the situation also add this statement to change the password:
SET PASSWORD = PASSWORD ( 'password');
However, this command has emerged this problem:
After the amount of Baidu know that the password level is too simple, if you insist on such a password to change the password level:
After logging database, enter
mysql> set global validate_password_policy = 0; // change password level mysql> set global validate_password_length = 4; // change the minimum password length
Then just enter the command:
SET PASSWORD = PASSWORD ( 'password');
Then again show databases; it is not being given the
Configure remote login:
The default MySQL root user can log on locally, if you want to remotely connect to simple settings, remote login here directly without the addition of other roles with the root.
Use the command:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '4008' WITH GRANT OPTION;
. * Means all tables in all libraries; To followed with a user name; with the ip address is behind @,% represents all ip address, identified by the latter is the password.
after that:
mysql> flush privileges;
注意:
需要注意mysql的配置文件中的bindaddress 的参数和skip-networking 配置
bindaddress : 设定哪些ip地址被配置,使得mysql服务器只回应哪些ip地址的请求),最好注释掉该参数或设置成为127.0.0.1以外的值
skip-networking : 如果设置了该参数项,将导致所有TCP/IP端口没有被监听,也就是说出了本机,其他客户端都无法用网络连接到本mysql服务器,所以应该注释掉该参数
添加3306端口:
命令:
firewall-cmd --zone=public --add-port=3306/tcp --permanent;
结果说没有运行防火墙:
那就先开防火墙咯:
systemctl status firewalld 查看防火墙状态 systemctl start firewalld 打开防火墙
然后再输入那个开放3306端口的命令就行了
firewall-cmd --zone=public --add-port=3306/tcp --permanent; firewall-cmd --reload 重启防火墙
最后的收尾:
1.我们刚开始说要写在yum的repository,用这个命令就行:
yum -y remove mysql57-community-release-el7-10.noarch
2.MySQL设一下utf8:
打开/etc/my.cnf也就是数据库的配置文件,然后在底部复制粘贴:
[mysqld] character_set_server=utf8 init_connect='SET NAMES utf8'
采用navicat新建数据库时,需要将编码方式设置为,字符集:utf8 -- UTF-8 Unicode ,排序规则:utf8_general_ci
3.阿里云的服务器中的安全组加入mysql连接的规则。这个很重要不然远程无法连接上。
4.配置文件的说明:
/etc/my.cnf 这是mysql的主配置文件
/var/lib/mysql mysql数据库的数据库文件存放位置
/var/log mysql数据库的日志输出存放位置