rpm -qa|grep -i mysql
rpm -e
[root@centos7 opt]# rpm -ivh MySQL-server-5.5.60-1.el7.x86_64.rpm --force --nodeps
warning: MySQL-server-5.5.60-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:MySQL-server-5.5.60-1.el7 ################################# [100%]
warning: user mysql does not exist - using root
warning: group mysql does not exist - using root
180716 1:09:52 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
180716 1:09:52 [Note] /usr/sbin/mysqld (mysqld 5.5.60) starting as process 1840 ...
180716 1:09:53 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
180716 1:09:53 [Note] /usr/sbin/mysqld (mysqld 5.5.60) starting as process 1847 ...
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h centos7 password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
Please report any problems at http://bugs.mysql.com/
[root@centos7 ~]# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
[root@centos7 ~]# cat /etc/passwd |grep mysql
mysql:x:996:993:MySQL server:/var/lib/mysql:/bin/bash
[root@centos7 ~]# cat /etc/group |grep mysql
mysql:x:993:
[root@centos7 ~]# mysqladmin --version
mysqladmin Ver 8.42 Distrib 5.5.60, for Linux on x86_64
[root@centos7 ~]#
/usr/bin/mysqladmin -u root password root
[root@centos7 ~]# chkconfig mysql on
[root@centos7 ~]# chkconfig --list | grep mysql
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
ntsysv
[root@centos7 ~]# cp /usr/share/mysql/my-huge.cnf /etc/my.cnf
[root@centos7 ~]# service mysql restart
[root@centos7 ~]# mysql -u root -p
字符集
mysql> show variables like 'character%';
mysql> show variables like '%char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
[root@centos7 ~]# ls -l /etc/my.cnf
-rwxr-xr-x. 1 root root 4697 Jul 16 01:41 /etc/my.cnf
[root@centos7 ~]# vim /etc/my.cnf
[client]
#password = your_password
port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set=utf8
# The MySQL server
[mysqld]
port = 3306
character_set_server=utf8
character_set_client=utf8
collation-server=utf8_general_ci
socket = /var/lib/mysql/mysql.sock
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 1M
table_open_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 32M
[mysql]
no-auto-rehash
default-character-set=utf8
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> create database db01;
Query OK, 1 row affected (0.00 sec)
mysql> use db01
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> create table user(id int not null,name varchar(20));
Query OK, 0 rows affected (0.01 sec)
mysql> show tables;
+----------------+
| Tables_in_db01 |
+----------------+
| user |
+----------------+
1 row in set (0.00 sec)
mysql> insert into user values(1,'z3');
Query OK, 1 row affected (0.01 sec)
mysql> select * from user;
+----+------+
| id | name |
+----+------+
| 1 | z3 |
+----+------+
1 row in set (0.00 sec)
mysql> drop database db01;
Query OK, 1 row affected (0.00 sec)
授权
mysql> use mysql;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'root' WITH GRANT OPTION;
mysql> flush privileges;
mysql> select host, user from user;
+-----------+------+
| host | user |
+-----------+------+
| % | root |
| 127.0.0.1 | root |
+-----------+------+
7 rows in set (0.00 sec)
打开防火墙的3306端口
[root@centos7 ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@centos7 ~]# firewall-cmd --reload
success
[root@centos7 ~]# firewall-cmd --zone=public --list-ports
3306/tcp